Why Won't this http post request work?

Posted by dubbeat on Stack Overflow See other posts from Stack Overflow or by dubbeat
Published on 2010-05-17T14:59:54Z Indexed on 2010/05/17 22:40 UTC
Read the original article Hit count: 349

Filed under:
|
|
|

Hi,

I'm wondering why this http post request won't work for my iphone app.

I know for a fact that the url is correct and that the variables I'm sending are correct but for some reason the request is not being recieved by the aspx page.

NSMutableString *httpBodyString;
    NSURL *url;
    NSMutableString *urlString;

    httpBodyString=[NSMutableString stringWithFormat:@"%@%@%@%@%@",@"?g=",promoValueObject.country,@"&c=",promoData.artistid,@"&d=iphone"];
    urlString=[[NSMutableString alloc] initWithString:@"http://www.mysite.com/stats_promo.aspx"];

    url=[[NSURL alloc] initWithString:urlString];
    [urlString release];

    NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
    [url release];

    [urlRequest setHTTPMethod:@"POST"];
    [urlRequest setHTTPBody:[httpBodyString dataUsingEncoding:NSISOLatin1StringEncoding]];
    //[httpBodyString release];

    NSURLConnection *connectionResponse = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

    if (!connectionResponse)
    {
        NSLog(@"Failed to submit request");
    }
    else
    {
        NSLog(@"--------- Request submitted ---------");
        NSLog(@"connection: %@ method: %@, encoded body: %@, body: %a", connectionResponse, [urlRequest HTTPMethod], [urlRequest HTTPBody], httpBodyString);
    }

© Stack Overflow or respective owner

Related posts about iphone

Related posts about http