0

我需要解析一个肥皂请求,但我遇到了以下问题,有人可以帮我解决这个问题,因为我是肥皂新手。如果您需要有关代码的任何其他信息,请告诉我

这是肥皂请求

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>
4

2 回答 2

0

我想把它放在评论中,但它太大了。这是我的肥皂请求代码:

    soapMsg =
    [NSString stringWithFormat:
     @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
     "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
     "<soap12:Body>"
     "<WebServiceMethod xmlns=\"http://tempuri.org/\">"
     "<MessageToServer><![CDATA[%@]]></MessageToServer>"
     "</WebServiceMethod>"
     "</soap12:Body>"
     "</soap12:Envelope>"
     ,encryptedString];

encryptedString 是我的服务器接收和解密的消息。WebServiceMethod 是我的 web 服务中的方法名称,MessageToServer 是 web 服务请求的对象的名称。

我也在使用ASIFormDataRequest而不是NSMutableURLRequest. 这可能会有所作为。ASIHTTP 库对我来说非常好。

还有一点。我的 Content-Type@"application/soap+xml; charset=utf-8" 老实说我不知道​​它应该是什么,在这方面你可能比我知道的更多。只是想我可能会提到它,因为它似乎是服务器不理解的标题。

于 2013-06-21T19:08:44.247 回答
0

尝试将 HTTP 字段 SOAPAction 添加到请求中:

[req setValue:@"http://spatialpoint.com/abc/locator/FindNearby" forHTTPHeaderField:@"SOAPAction"];

也考虑检查一下这个项目

于 2013-06-21T20:26:25.637 回答