从服务器获取数据时出错 [英] Error in getting data from the server

查看:100
本文介绍了从服务器获取数据时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am sending some data to my server using POST method. Code is as follows:

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];

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

I am not receiving the correct data in from the server.

接收代码为:

- (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>

推荐答案

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

You can't just test a SOAP service by sending an arbitrary string. All you are proving is that the URL is pointing to a server which is expecting to receive SOAP messages. You need to look at the server specification and create the appropriate SOAP payload to be sent. This should replace your current content in stringData.

这篇关于从服务器获取数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆