服务器无法识别iPhone中HTTP Header SOAPAction的值?
问题描述:
我尝试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?
答
NSURL *url = [NSURL URLWithString:@"https://servername.com/WebService/WebServicename.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
[theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"servername.com/Hello" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
这里是链接,
http://abhicodehelp.blogspot.com/2010/12/handling-soap-with-iphone.html
这可能会帮助你..
答
如果这是你自己的网络服务,检查是否在您的 “servername.com/Hello”查询等于Web服务中的命名空间。
在ASP.Net它定义一样:
[WebService(Namespace="servername.com/Hello")]
你试过没有提供SOAPAction头呢? – slf 2010-07-20 13:36:51
我知道它的偏离主题的建议,但为什么你使用网络连接它使事情更方便 – amar 2013-04-15 05:56:48