1

我正在尝试让我的 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

4

1 回答 1

0

- 试试这个肯定会帮助你:

NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                             "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><Service xmlns=\"http://tempuri.org/\">"
                             "<xmlstring>&lt;silent&gt;&lt;action&gt;logon&lt;/action&gt;&lt;gameid&gt;mygame&lt;/gameid&gt;&lt;gpassword&gt;gamepwd&lt;/gpassword&gt;&lt;data&gt;&lt;username&gt;abcd@abc.com&lt;/username&gt;&lt;password&gt;a&lt;/password&gt;&lt;/data&gt;&lt;/silent&gt;</xmlstring></Service>"
                             "</SOAP-ENV:Body>"
                             "</SOAP-ENV: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]];
于 2013-08-24T06:17:06.727 回答