我嘗試Web服務連接到我的代碼,我得到了錯誤的服務器無法識別iPhone中HTTP Header SOAPAction的值?
「服務器無法識別的HTTP頭SOAPAction的價值」
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">\n"
"<soap:Body>\n"
"<Hello xmlns=\"http://viium.com/\">\n"
"<name>%@</name>\n"
"</Hello>\n"
"</soap:Body>\n"
"</soap:Envelope>\n", @"new"
];
NSLog(soapMessage);
NSURL *url = [NSURL URLWithString:@"http://viium.com/WebService/HelloWorld.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://viium.com/Hello" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
請指引我錯過了什麼IAM?
你試過沒有提供SOAPAction頭呢? – slf 2010-07-20 13:36:51
我知道它的偏離主題的建議,但爲什麼你使用網絡連接它使事情更方便 – amar 2013-04-15 05:56:48