0

I'm trying to make a POST request using NSURLConnection. I use Charles to debug and Charles every time says that the method is GET. I've tried all different ways and can't get it to work. I am NOT using JSON.

-(void)getList
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    NSURL *url = [NSURL URLWithString:@"http://example.com/api/getList"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    NSString *radius = @"15";
    NSString *latitude = @"-117.820833";
    NSString *longitude = @"34.001667";

    NSString *parameters = [NSString stringWithFormat:@"longitude=%@&latitude=%@&radius=%@", longitude,latitude, radius];
    NSLog(@"PARAMS = %@", parameters);

    NSData *data = [parameters dataUsingEncoding:NSUTF8StringEncoding];

    [request setHTTPMethod:@"POST"];
    [request setValue:@"text/plain" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:data];

    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    NSString *responseString = [[NSString alloc]initWithData:result encoding:NSUTF8StringEncoding];

    NSLog(@"RESULT = %@", responseString);


}

Does anybody know what am I doing wrong? When I access my web service it seems like I'm not posting anything. I'm getting empty response.

Please help with any ideas. I pretty much have to make a simple POST request. Maybe someone can help me debug this better.

4

1 回答 1

0

如果服务器出于某种原因(可能是身份验证)重定向您的请求,则POST信息可能会丢失。

于 2013-06-27T20:49:33.403 回答