passing parameter to the web service working code
again i am trying with soap method, but this time i downloaded the cha开发者_开发问答rles and observe the request that i create from my code. Chales showing "failed to parse data(org.xml.sax.saxparser exception:content is not allowed in prolog)"
here is my code:
NSString *soapMsg = [[NSString alloc] initWithFormat:@"\n" "\n" "" "\n" "%@\n" "%@\n" "%@\n" "%@\n" "\n" "\n" "\n",str1,str2,str3,str4]; NSLog(soapMsg); NSURL *url = [NSURL URLWithString:@"http://192.168.0.218:84/WebServiceCustomerByAmit/Service.asmx?op=InsertCustomerInformation"]; NSLog(@"url. . . .%@", url); NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; NSLog(@"req....%@", req); NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]]; NSLog(@"msgLength. . .%@", msgLength); [req addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [req addValue: @"http://tempuri.org/InsertCustomerInformation" forHTTPHeaderField:@"SOAPAction"]; [req addValue: msgLength forHTTPHeaderField:@"Content-Length"]; [req setHTTPMethod:@"POST"]; [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]]; NSLog(@"req....%@", req); NSError *error; NSURLResponse *response; //NSData *urlData=[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; if( theConnection ) { //webData = [[NSMutableData data] retain]; NSLog(@"theConnection is OK"); } else { NSLog(@"theConnection is NULL"); } if(!response){ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Failed to Connect to the Internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } else{ UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Connection Successful" message:@"Connected to the Internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert1 show]; [alert1 release]; } }
help!! thanks in advance!!
You are asking how to include ASIHTTPRequest in your project, right? Copy and paste ASIHTTPRequest's folder in your project's folder and add this in your code:
#import "ASIHTTPRequest.h"
Note that ASIHTTPRequest is an external library and not part of the iOS SDK.
精彩评论