0

i have tried to send username and password along with person image to server using ASIHTTPRequest and i have written some code but it's not working data is not sent to server please some body help me with example code

-(void)service_Call{

    NSString *urlStr = [NSString URLWithString:urlstring];
    NSLog(@"urlStr --->> %@",urlStr);

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlStr]];

   [request setRequestMethod:@"POST"];
   [request setPostValue:self.FnameTxt.text forKey:@"username"];
   [request setPostValue:self.LnameTxt.text forKey:@"password"];

   NSString *fileName = @"iphone.jpg";
   // Upload an image
   UIImage *img = [UIImage imageNamed:fileName];
   NSData *imageData = UIImageJPEGRepresentation(img, 90);
   [request setData:imageData withFileName:fileName andContentType:@"image/jpeg" forKey:@"image"];
   [request setDelegate:self]; 
   [request startAsynchronous];
   [MBProgressHUD showHUDAddedTo:self.view animated:YES];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    // Use when fetching text data
    NSString *responseString = [request responseString];
    NSLog(@"response: %@", responseString);

    // Use when fetching binary data
    NSData *responseData = [request responseData];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
}

But data is not sending to server please help me somebody if there is any error i code

Mayank Patel
  • 3,868
  • 10
  • 36
  • 59

1 Answers1

0

You should use AFNetworking instead of ASIHTTPRequest, and you will find how handy it can be used.

Also, normally imageData should be sent as base64 string, if you send image by NSData, how your server side handle it?

Caesar
  • 101
  • 2