我正在尝试让我的 iPhone 应用程序连接到我的 Web 服务。我对这个 Web 服务没有太多经验,所以这就是我在这里寻求信息/帮助的原因。
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">\n"
"<soap:Body>\n"
"<silent xmlns="http://tempuri.org/">"
"<action>logon</action>"
"<gameid>mygame</gameid>"
"<gpassword>gamepwd</gpassword>"
"<data>"
"<username>abc@abc.com</username>"
"<password>a</password>"
"</data>"
"</silent>"
"</soap:Body>"
"</soap:Envelope>"];
NSURL *url1 = [NSURL URLWithString:@"http://mywebsite.com/Service.svc"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url1];
NSString *msgLength1 = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/ISilentManagerAPI/Service" forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength1 forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
此代码总是返回status code 415
,我做错了什么?
PS。
这是在Android中运行良好的链接,获取java.io.IOException:HTTP请求失败,HTTP状态:ksoap2中的404同时将xml数据传递给soap1.2 android