我需要解析一個肥皂請求,但我有以下問題,有人可以幫助我解決這個問題,因爲我是肥皂新手。我知道如果您需要關於代碼的任何其他信息肥皂分析問題
這裏是SOAP請求
POST /LocatorAPI/LocatorService.asmx HTTP/1.1
Host: staging2.abc.spatialpoint.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://spatialpoint.com/abc/locator/FindNearby"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<FindNearby xmlns="http://spatialpoint.com/abc/locator/">
<request> <Token>string</Token>
</request>
</FindNearby>
</soap:Body>
</soap:Envelope>
這裏是我的目標C代碼。
NSString* soapMessage =
[NSString stringWithFormat:@"%@%@%@%@%@%@%@%@%@%@",
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>",
@"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">",
@"<soap:Body>",
@"<FindByProperty xmlns=\"http://spatialpoint.com/abc/locator/ \">",
@"<request>",
@"<Token>",
theRadius,
@"</Token>",
@"</request>",
@"</FindByProperty>",
@"</soap:Body>",
@"</soap:Envelope>"];
NSURL *url = [NSURL URLWithString:@"http://staging2.abc.spatialpoint.com/LocatorAPI/LocatorService.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
// HTTP headers
NSString *messageLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:messageLength forHTTPHeaderField:@"Content-Length"];
// method = POST
[req setHTTPMethod:@"POST"];
// BODY
[req setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
// send request
self.connection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (self.connection != nil)
{
self.receivedData = [NSMutableData data];
}
else
{
[[UIApplication sharedApplication]
setNetworkActivityIndicatorVisible:NO];
}
我得到這個錯誤。
2013-06-19 02:22:49.942 SoapClient[42229:c07] Response:
2013-06-19 02:22:49.943 SoapClient[42229:c07] <?xml version="1.0" encoding="utf-8"?>
<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><soap:Fault>
<faultcode>soap:Client</faultcode><faultstring>Server did not recognize the value of HTTP
Header SOAPAction: .</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
我不能使用ASIHTTP不再受支持。 – Anil
你爲什麼設置消息長度兩次?並檢查我的編輯另一點可能會幫助你,可能不會。 – Putz1103
消息長度兩次是錯字,只是更新了代碼。 – Anil