1

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>
Wain
  • 118,658
  • 15
  • 128
  • 151
Saurabh Gulia
  • 285
  • 1
  • 3
  • 13
  • can you post all your delegates methods of NSURLConnection? – Ilario Jan 31 '14 at 11:21
  • Also, what's getting printed as newStr (if its getting printed that is)? – Anil Jan 31 '14 at 11:23
  • @Anil tis is what i am getting: ns1:Client.NoSOAPAction no SOAPAction header! – Saurabh Gulia Jan 31 '14 at 11:25
  • @Ilario there is nothing in any other delegate method. Can you tell me where i am wrong, i mean am the above output i.e in the body. It was supposed to come something different. Please help – Saurabh Gulia Jan 31 '14 at 11:27
  • check this out? http://stackoverflow.com/questions/16445945/no-action-header-was-found-error-message-while-using-soap-webservice – Anil Jan 31 '14 at 11:27
  • Did u ensure u are sending proper xml data to server, please check stringData – Swati Jan 31 '14 at 11:28
  • try to send ::::: [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; No need to send ::: charset=utf-8 – Swati Jan 31 '14 at 11:28
  • Are you really just sending `@"Hello";` ? – Wain Jan 31 '14 at 11:30
  • @Wain i have to send username and password, but for testing purpose i am just sending @"Hello" – Saurabh Gulia Jan 31 '14 at 11:35
  • @Swati same output continues!! do you what it means when it is written : no SOAPAction header! .what exactly it means? do i have to edit my code with smthg? – Saurabh Gulia Jan 31 '14 at 11:37
  • just look into @Swati's given link you will understand how to get response from soap api – Maul Jan 31 '14 at 11:49

1 Answers1

2

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.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • ok i accept your point, can you tell me the code snippet that i have written above to POST data to server is correct? Do i have to set any value for SOAP Action also like this: [request setValue:@"application/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; Actually first time i am dealing with server.Sorry for any childish question. – Saurabh Gulia Jan 31 '14 at 11:47
  • The code is generally correct. The headers and body content that you send are dependent on the server expectation. Generally you need to set `Content-Type` (XML or SOAP XML) and `Content-Length`. – Wain Jan 31 '14 at 11:50