我一直在尝试使用Alamofire
发出xml请求。但是,我遇到<soap:Text xml:lang="en">Server was unable to process request. ---> Root element is missing.</soap:Text>
错误。实际上,这是我在ios中关于xml请求的第一次体验。如何在没有问题的情况下实现此请求。这是我的代码;
Alamofire.request(.POST, "http://example.com/WS.asmx?op=AuthenticateUser", parameters: nil, encoding: .PropertyList(.XMLFormat_v1_0, 0), headers: ["Username": "username", "Password": "password" , "AuthenticatedToken" : "123123"])
.responsePropertyList { response in
let xml = SWXMLHash.parse(response.data!)
print(xml)
}
我做错了什么?你能帮帮我吗?
感谢您的回答
祝你好运
答案 0 :(得分:0)
试试吧
Alamofire.request(.POST, "http://example.com/WS.asmx?op=AuthenticateUser",
parameters: nil,
// Try ->
encoding: .Custom({
(convertible, params) in
let mutableRequest = convertible.URLRequest.copy() as! NSMutableURLRequest
mutableRequest.HTTPBody =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"urn:sap-com:document:sap:rfc:functions\"><SOAP-ENV:Body>
<soap:Text xml:lang="en">Server was unable to process request. ---> Root element is missing.</soap:Text>
</SOAP-ENV:Body></SOAP-ENV:Envelope>".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
return (mutableRequest, nil)}),
headers:
["Username": "username",
"Password": "password" ,
"AuthenticatedToken" : "123123"])
.responsePropertyList { response in
let xml = SWXMLHash.parse(response.data!)
print(xml)
}