问题
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"];
I am using
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:theRequest];
The error I am getting is:
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}
I understand that 400 is for bad request, is there something that I need to add?
For .net service do we need to send anything else like for Android they have soapobject.dotnet=true
回答1:
The most common reason for a 400 Bad Request error is because the URL was typed wrong or the link that was clicked on points to a URL with some kind of mistake in it.
May be your url contains a white space at the starting
回答2:
Friends Found the answer:::
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 ">".
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:@">"];
Cheers friends, thanks for trying... ATB
来源:https://stackoverflow.com/questions/19682044/getting-error-while-sending-soap-request