ASIHttpRequest not passing data

112 views Asked by At
 NSURL *url = [NSURL URLWithString:@"http://test.com/misc/app/ws/ws_user_registration.php?"];
     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

     [request setRequestMethod:@"POST"];
     [request setDelegate:self];

  [request appendPostData:[[NSString stringWithFormat:@"{\"user_name\":\"%@\",\"user_tag_status\":\"%@\",\"description\":\"%@\",\"mobile_number\":\"%@\",\"device_type\":\"%@\",\"device_id\":\"%@\",\"device_token\":\"%@\",\"os\":\"%@\",\"os_version\":\"%@\",\"image_data\":\"%@\",\"user_id\":\"%@\"}",self.phnNumTxtFld.text,@"live",@"description",self.phnNumTxtFld.text,@"iPhone",appDelegate.deviceID,appDelegate.deviceToken,@"iOS",[UIDevice currentDevice].systemVersion,[data base64EncodedString],@""] dataUsingEncoding:NSUTF8StringEncoding]];
     [request setDidFinishSelector:@selector(getTreeRequestFinished:)];
     [request setDidFailSelector:@selector(getTreeRequestFailed:)];
     [request startAsynchronous];

appendPostData: passing NSData but server not getting this data.

1

There are 1 answers

1
Bhumeshwer katre On BEST ANSWER

To post data use ASIFormDataRequest

 NSURL *url = [NSURL URLWithString:@"http://test.com/misc/app/ws/ws_user_registration.php?"];

 ASIFormDataRequest* asiRequest = [ASIFormDataRequest requestWithURL: url];
 [asiRequest setPostFormat:ASIMultipartFormDataPostFormat];
 [asiRequest addData:DATA_TO_SEND withFileName:FILE_NAME andContentType:FILE_CONTENT_TYPE forKey:YOUR_FILE_UPLOADKEY;

 [asiRequest setDidFinishSelector:@selector(connectionFinishedLoading:)];// called when connection successfully got finished and recieve resoponse
 [asiRequest setDidFailSelector:@selector(requestWentWrong:)]; // called when connection went wrong due to bad url connection or timeout, etc.

 [asiRequest setDelegate:self]; 
 [asiRequest startAsynchronous];

For more info read asihttp docs