2013-10-30 165 views
0

將SOAP請求發送到.net Web服務時出錯,我在這裏丟失了什麼?發送SOAP請求時出錯

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 =真

回答

0

友空白找到了答案:::

有的時候在傳輸肥皂中的XML出現問題:身上。快速和骯髒的解決方案來解決它是包裹XML(只是你要傳遞的參數,如溫度或貨幣代碼等)在CDATA部分,以這種方式:::

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

據大多數博客,單獨應該工作,但如果如果還是不行,改回在你的web服務,如果您有機會獲得它,它不爲你工作,

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

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

乾杯朋友,感謝您試用... ATB

+0

完美地工作! :) – grk

0

一個400錯誤請求錯誤最常見的原因是因爲URL被輸入錯誤或鏈接被點擊點到一個URL中的某種錯誤。

可能是您的網址包含起始

+0

謝謝,但URL不帶任何空格..而當我把網址在瀏覽器中,它進入正確的網站 – grk

+0

好的。檢查網址是否正確 – manujmv

+0

將您的內容類型更改爲text/xml – manujmv