0

I need to send a pic to a server via HTTP post, but I am getting a response from server saying that I used POST+GET. Any ideas what I did wrong? Here is my code.

- (void)sendMessagesWithImg
{
    NSMutableData *body = [NSMutableData data];

    UIImage *imgColor = [UIImage imageNamed:@"imgbar.png"];



        UIImage * imageToPost = [[UIImage alloc] init];

       imageToPost = [self convertImageToGrayScale:imgColor];

        // add image data
        NSData *imageData = UIImageJPEGRepresentation(imageToPost, 1.0);
       if (imageData) {

            [body appendData:imageData];

       }

    [imgView setImage:imageToPost];

    [body appendData:imageData];


      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"URL"]];
    [request setHTTPBody:body];
    [request setHTTPMethod:@"POST"];

    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [conn start];   
}

Server response

More than the maximum number of request parameters (GET plus POST) for a single request ([512]) were detected.

user2067051
  • 99
  • 2
  • 15

1 Answers1

0

You append the imageData for two times. Delete the second.

[body appendData:imageData];

In any case try also with this:

// set the content-length
NSString *postLength = [NSString stringWithFormat:@"%d", [body length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];

and read this post..you have to attach others parameters probably:

ios Upload Image and Text using HTTP POST

Community
  • 1
  • 1
Matteo Gobbi
  • 17,697
  • 3
  • 27
  • 41