【发布时间】:2015-02-13 09:58:32
【问题描述】:
我在 ios 中使用 swift 调用服务,如下所示, 我的服务在 android 版本上运行良好,但是当我尝试使其与 ios 一起使用时,它总是返回错误代码 400
下面是ios版本代码
var soapMessage = "<?xml version='1.0' encoding='UTF-16'?><soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><GetAirports xmlns='http://groundspan.com/groundspan'/></soap:Body></soap:Envelope>"
// var urlString = "http://example.com/myeservice.svc"
var urlString = "http://example.com/myservice.svc?"
var nameSpace = "http://example.com/service"
var methodNam = "GetAirports"
var msgLength = String(countElements(soapMessage))
var url = NSURL(string: urlString)!
println("Url : \(url)")
var theRequest = NSMutableURLRequest(URL: url)
theRequest.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
theRequest.addValue(msgLength, forHTTPHeaderField: "Content-Length")
theRequest.addValue("http://example.com/service/IGroundSpanProcessorService/\(methodNam)", forHTTPHeaderField: "SOAPAction")
theRequest.HTTPMethod = "POST"
theRequest.HTTPBody = soapMessage.dataUsingEncoding(NSUTF16StringEncoding, allowLossyConversion: false)
var connection = NSURLConnection(request: theRequest, delegate: self, startImmediately: true)
connection?.start()
if (connection == true) {
var mutableData : Void = NSMutableData.initialize()
}else{
println("Error in connection")
}
它总是进入连接块的 else 和连接中的五次错误并得到错误代码 400 错误。
请帮帮我。
【问题讨论】: