发送SOAP请求时出错

时间:2013-10-30 12:18:09

标签: ios .net soap

将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

2 个答案:

答案 0 :(得分:0)

400 Bad Request错误的最常见原因是因为输入的网址错误或点击的链接指向某个网址时出现某种错误的网址。

可能是您的网址在起始处包含空格

答案 1 :(得分:0)

朋友找到答案:::

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

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

根据大多数博客的说法,只有这样才有用,但如果它不适合你,

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

如果仍然无效,请在您的网络服务中更改它们,如果您有权访问它。

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

干杯啦,感谢您的努力... ATB