Error in getting data from the server

匿名 (未验证) 提交于 2019-12-03 09:06:55

问题:

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.

The code for receiving is:

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

The response I receive is:

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

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!