0

将 SOAP 请求发送到 .net Web 服务时出错,我在这里遗漏了什么吗?

 NSString *str1 = [NSString stringWithFormat:@"<UserId>%@</UserId><Password>%@</Password><Referal>%@</Referal>",u,p,r];

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>""<getData xmlns=\"http://tempuri.org/\">\n"" <reqXML>%@</reqXML>""</getData>\n""</soap:Body>""</soap:Envelope>", str1];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

[theRequest setHTTPMethod:@"POST"];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue: @"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

我在用

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:theRequest];

我得到的错误是:

Error Domain=com.alamofire.networking.error Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x7536290 {NSErrorFailingURLKey=http://213.171.205.156/webservice_booking_affiliate_live/bookingengine.asmx, NSLocalizedDescription=Expected status code in (200-299), got 400}

我知道 400 是错误的请求,我需要添加什么吗?

对于 .net 服务,我们是否需要像 Android 一样发送任何其他内容,它们有soapobject.dotnet=true

4

2 回答 2

0

朋友找到答案了:::

有时在soap:body 中传输XML 时确实会出现问题。修复它的快速而肮脏的解决方案是将xml(仅您要传递的参数,如温度或货币代码等)包装在CDATA部分中,以这种方式:::

<![CDATA[%@]]>. This would mean that the XML parser will not parse that section. 

根据大多数博客的说法,仅此一项就可以了,但是如果对您不起作用,

replace the < and > with "&lt;" and "&gt;". 

如果它仍然不起作用,如果您可以访问它,请在您的 Web 服务中将它们改回。

query = [query stringByReplacingOccurrencesOfString:@"<" withString:@"&lt;"];
query = [query stringByReplacingOccurrencesOfString:@">" withString:@"&gt;"];

干杯朋友,感谢您的尝试... ATB

于 2013-11-02T05:28:15.267 回答
0

400 Bad Request 错误的最常见原因是 URL 输入错误或点击的链接指向的 URL 存在某种错误。

可能是您的网址在开头包含一个空格

于 2013-10-30T12:23:36.437 回答