Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift中Soap请求的错误代码500_Ios_Swift_Web Services_Soap_Request - Fatal编程技术网

Ios Swift中Soap请求的错误代码500

Ios Swift中Soap请求的错误代码500,ios,swift,web-services,soap,request,Ios,Swift,Web Services,Soap,Request,我正在尝试执行一个soap请求,该请求调用加密函数并返回一个值。当我向邮递员提出请求时,它起作用了。然而,我从邮递员那里得到了代码,但它返回了错误代码500。我想问题可能出在postData中,我在双引号前加了\号。 代码: let头=[ “内容类型”:“文本/xml”, “缓存控制”:“无缓存”, “邮递员代币”:“4d266611-ea55-0c8a-7879-eac8bf387ed0” ] 让postData=NSData(数据:“RequestIsValid29:01:2015 16:3

我正在尝试执行一个soap请求,该请求调用加密函数并返回一个值。当我向邮递员提出请求时,它起作用了。然而,我从邮递员那里得到了代码,但它返回了错误代码500。我想问题可能出在postData中,我在双引号前加了\号。 代码:

let头=[
“内容类型”:“文本/xml”,
“缓存控制”:“无缓存”,
“邮递员代币”:“4d266611-ea55-0c8a-7879-eac8bf387ed0”
]
让postData=NSData(数据:“RequestIsValid29:01:2015 16:31”。数据(使用:String.Encoding.utf8)!)
let request=NSMutableURLRequest(url:NSURL(字符串:)http://mobileexam.veripark.com/mobileforeks/service.asmx“”!作为URL,
cachePolicy:.useProtocolCachePolicy,
timeoutInterval:10.0)
request.httpMethod=“POST”
request.allHTTPHeaderFields=标题
request.httpBody=postData作为数据
让session=URLSession.shared
让dataTask=session.dataTask(其中:request作为URLRequest,completionHandler:{(数据,响应,错误)->Void in
如果(错误!=nil){
打印(错误)
}否则{
让httpResponse=响应为?HTTPURLResponse
打印(httpResponse)
}
})
dataTask.resume()
错误代码:

    <NSHTTPURLResponse: 0x608000222300> { URL: http://mobileexam.veripark.com/mobileforeks/service.asmx } { status code: 500, headers {
    "Cache-Control" = private;
    Connection = "Keep-Alive";
    "Content-Length" = 1802;
    "Content-Type" = "application/soap+xml; charset=utf-8";
    Date = "Mon, 28 Aug 2017 14:57:47 GMT";
    Server = "Microsoft-IIS/7.5";
    "X-AspNet-Version" = "4.0.30319";
    "X-Powered-By" = "ASP.NET";
} })
{URL:http://mobileexam.veripark.com/mobileforeks/service.asmx }{状态代码:500,标题{
“缓存控制”=专用;
连接=“保持活动”;
“内容长度”=1802;
“内容类型”=“应用程序/soap+xml;字符集=utf-8”;
日期=“2017年8月28日星期一14:57:47 GMT”;
Server=“Microsoft IIS/7.5”;
“X-AspNet-Version”=“4.0.30319”;
“X-Powered-By”=“ASP.NET”;
} })
你试过了吗


[lobj_请求设置值:@“gzip”用于HttpHeaderField:@“接受编码”]

正如我在问题中提到的。问题是字符串中的xml部分。我添加了\before“,并在需要新行时添加了\r。下面是XML的正确字符串版本

"\rhttp://www.w3.org/2001/XMLSchema-instance\“xmlns:xsd=\”“xmlns:soap=\”“>\r”\rhttp://tempuri.org/\“>\r请求验证29:01:2015 16:31\r\r”

因此,问题的最终工作代码是:

let poststring = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">\r<soapenv:Header/> <soapenv:Body>\r<tem:GetForexStocksandIndexesInfo> <tem:request>\r<tem:IsIPAD>true</tem:IsIPAD>\r<tem:DeviceID>test</tem:DeviceID>\r<tem:DeviceType>ipad</tem:DeviceType>\r<tem:RequestKey>\(self.encrypt_code!)</tem:RequestKey>\r<tem:RequestedSymbol>\(name)</tem:RequestedSymbol>\r<tem:Period>Month</tem:Period> </tem:request>\r</tem:GetForexStocksandIndexesInfo> </soapenv:Body>\r</soapenv:Envelope>"
let postData = NSData(data: poststring.data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: NSURL(string: "http://mobileexam.veripark.com/mobileforeks/service.asmx")! as URL,
                                      cachePolicy: .useProtocolCachePolicy,
                                      timeoutInterval: 10.0)
let poststring=“\r\r\rtrue\rtest\ripad\r\(self.encrypt\u code!)\r\(name)\rMonth\r\r”
让postData=NSData(数据:poststring.data(使用:String.Encoding.utf8)!)
let request=NSMutableURLRequest(url:NSURL(字符串:)http://mobileexam.veripark.com/mobileforeks/service.asmx“”!作为URL,
cachePolicy:.useProtocolCachePolicy,
timeoutInterval:10.0)

设置“内容类型”URLRequest:?我更改了代码,你能检查一下吗?@iOSDeveloper是的。确切的问题是什么?@iOSDeveloper我在答案中添加了工作代码。请检查。我改变了问题,你能检查一下吗?我刚试着把它放进我的网络浏览器,看起来有一些错误。你的网址正确吗?是的。我和邮递员试了一下,它成功地返回了。我认为问题在于,在我的postdata中,我在“我在这个答案中找到了一些教程:
let poststring = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">\r<soapenv:Header/> <soapenv:Body>\r<tem:GetForexStocksandIndexesInfo> <tem:request>\r<tem:IsIPAD>true</tem:IsIPAD>\r<tem:DeviceID>test</tem:DeviceID>\r<tem:DeviceType>ipad</tem:DeviceType>\r<tem:RequestKey>\(self.encrypt_code!)</tem:RequestKey>\r<tem:RequestedSymbol>\(name)</tem:RequestedSymbol>\r<tem:Period>Month</tem:Period> </tem:request>\r</tem:GetForexStocksandIndexesInfo> </soapenv:Body>\r</soapenv:Envelope>"
let postData = NSData(data: poststring.data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: NSURL(string: "http://mobileexam.veripark.com/mobileforeks/service.asmx")! as URL,
                                      cachePolicy: .useProtocolCachePolicy,
                                      timeoutInterval: 10.0)