How to access a SOAP webservice from my iPhone app
I am new to iPhone application development and also this stackoverflow,if I made any mistakes sorry. I have some of the questions
1) Do I need to install any other external framework into my application. I am using SDK Simulator 4.2
2) I have gone through some of the material which was posted here, I found some code and I made some modification to suits my application When I am requesting for a URL it is returning me NULL.开发者_运维百科
3) My task is to send a three parameters into database.
NSString *post =[NSString stringWithFormat:@"?FirstName=%@?Surname=%@?IDNumber=%@?DOB=%@",namestring,surnamestring,cidstring,dobstring];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"Post Length:",[postData length]);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.esoft.co.za/MDS/Service1.asmx?op=InsertSuppliers"]];
[request setHTTPMethod:@"GET"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"response data is: %@",[responseData length] );
NSString *data = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Data: %@",data);
Thanks in Advance Guys...Please provide me any sample code or material..
I think it's because you're trying to send invalid request. Just try to check and log error message to see what's wrong.
What you're trying to do is to send POST data over GET request, which is wrong anyway. I'm also not sure about those "Post" data format, but when you'll check error message you'll find what's wrong.
NSLog(@"Request failed with error: %@", [err localizedDescription]);
best
精彩评论