问题描述
在将SOAP请求发送到.net Web服务时出错,我在这里遗漏了什么吗?
Getting error while sending SOAP request to a .net web service, am I missing something here?
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是针对错误的请求,是否需要添加一些内容?
I understand that 400 is for bad request, is there something that I need to add?
对于.net服务,我们是否需要发送其他内容,例如对于Android,它们具有soapobject.dotnet = true
For .net service do we need to send anything else like for Android they have soapobject.dotnet=true
推荐答案
朋友找到了答案:::
Friends Found the answer:::
有时在soap:body中传输XML时确实会出现问题.解决该问题的快速而肮脏的解决方案是将xml(仅要传递的参数,例如温度或货币代码等)包装在CDATA部分中,方法是:::
Sometimes problems do occur while transmitting XML within the soap:body. The quick and dirty solution to fix it was to wrap the xml (only the parameters that you want to pass, like temperature or currency codes etc...) in a CDATA section, in this way:::
<![CDATA[%@]]>. This would mean that the XML parser will not parse that section.
根据大多数博客,仅此一项应该有效,但如果不适用于您,
According to most blogs, that alone should work but if it doesn't work for you,
replace the < and > with "<" and ">".
如果仍然无法正常运行,请在有权访问的情况下将其更改回Web服务.
If it still doesn't work, change them back in your web service if you have access to it.
query = [query stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
query = [query stringByReplacingOccurrencesOfString:@">" withString:@">"];
欢呼朋友,感谢您尝试... ATB
Cheers friends, thanks for trying... ATB
这篇关于发送SOAP请求时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!