0

Hi I'm using this sample to upload a photo into my server Objective C: How to upload image and text using HTTP POST?

However, I fail to grab parameter1 and parameter2 using $_POST or $_REQUEST

NSString *param1 = @"parameter text"; [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"parameter1\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:param1] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

Is there something else I need to use aside from $_POST and $_REQUEST to grab the parameters?

Community
  • 1
  • 1
martti d
  • 2,552
  • 2
  • 17
  • 20

1 Answers1

0

Try the following :

-(void) httpRequestSender{
    NSString *par1 = @"test1";
    NSString *par2 = @"test2";
    NSString *requestedURL=@"http://something/post.php";
    NSString *urlString =[NSString stringWithFormat:@"%@?par1=%@&par2=%@",requestedURL,par1,par2];
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
    [request setHTTPMethod:@"GET"];

    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData *result = [NSURLConnection sendSynchronousRequest:request
        returningResponse:&response error:&error];
    NSString *resultString = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
    //resultString is the returned buffer from calling the page
[request release];

}
Ashraf
  • 2,612
  • 1
  • 20
  • 35