从服务器获取数据时出错

时间:2014-01-31 11:14:35

标签: ios iphone soap

我使用POST方法将一些数据发送到我的服务器。代码如下:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"<myServer ip>"]];
[request setValue:@"application/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
NSString *stringData = @"Hello";
NSData *requestBodyData = [stringData dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPBody = requestBodyData;
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[conn start];

我没有从服务器收到正确的数据。

接收代码是:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    NSLog(@"didFinishLoading Called");
    NSString* newStr = [[NSString alloc] initWithData:responseData
                                              encoding:NSUTF8StringEncoding];
    NSLog(@"data received is = %@",newStr);
}

我收到的回复是:

<soapenv:Body>
    <soapenv:Fault>
        <faultcode xmlns:ns1="xml.apache.org/axis/">ns1:Client.NoSOAPAction</…;
        <faultstring>no SOAPAction header!</faultstring>
        <detail>

1 个答案:

答案 0 :(得分:2)

您不能通过发送任意字符串来测试SOAP服务。您要证明的是,URL指向希望接收SOAP消息的服务器。您需要查看服务器规范并创建要发送的相应SOAP负载。这应该替换stringData中的当前内容。