开发者

ASIFormDataRequest has empty POST body

I had a working MacOS application that was making a POST to a server. I changed the URL of the POST and things stopped working.

I downloaded Tuffcode (a sniffer), which shows me that when using the new URL, the POST BODY is empty!

- (IBAction)grabURLInBackground:(id)sender
{
    NSURL *url = [NSURL URLWithString:@"url1"];
    //NSURL *url = [NSURL URLWithString:@"url2"];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setDelegate:self];
    [request addRequestHeader:@"Content-Language" value:@"en"];
    [request addRequestHeader:@"Content-Type" value:@"application/x-www-form-urlencoded"];
    [request addRequestHeader:@"Connection" value:@"keep-alive"];
    [request addRequestHeader:@"Cookie" value: [NSString stringWithFormat:@"botcust2=%@", sn]];
    [request setShouldAttemptPersistentConnection:NO];

    [request addPostValue:[input stringValue] forKey:@"input"];
    [input setStringValue:@""];
    [request startAsynchronous];

}

Switching from url1 to url2 goes from a well formed POST BODY to an empty POST BODY. How could that be? How can the URL determine what gets sent? At first I thought it was the new server that did not interpret the POST correctly, but if Tuffcode is correct, the application doesn't even send the data??

Or maybe there is something I don't know about how HTTP works? I am confused...

Some logs:

2011-07-29 12:28:36.018 ChatBot[6764:707] [STATUS] Starting asynchronous request <ASIFormDataRequest: 0x10188d420>
2011-07-29 12:28:36.021 ChatBot[6764:6403] 
==== Building an application/x-www-form-urlencoded body ====
input=hello
==== End of application/x-www-form-urlencoded body ====
2011-07-29 12:28:36.027 ChatBot[6764:6403] [CONNECTION] Request <ASIFormDataRequest: 0x10188d420> will not use a persistent connection
2011-07-29 12:28:36.280 ChatBot[6764:6403] [STATUS] Request <ASIFormDataRequest: 0x10188d420> finished uploading data
2011-07-29 12:28:36.374 ChatBot[6764:6403] [STATUS] Request <ASIFormDataRequest: 0x10188d4开发者_C百科20> received response headers
2011-07-29 12:28:36.375 ChatBot[6764:6403] [STATUS] Request <ASIFormDataRequest: 0x10188d420> finished downloading data (0 bytes)
2011-07-29 12:28:36.376 ChatBot[6764:6403] [STATUS] Request finished: <ASIFormDataRequest: 0x10188d420>


Why are you setting the string to null right after you post?

[request addPostValue:[input stringValue] forKey:@"input"];
[input setStringValue:@""];

It's possible that the compiler is switching the order of those two lines and you are submitting that null string. Why don't you try running it with the 2nd line removed?


A little after the fact, but I've just run into something similar. Like you I had a ASIHTTPRequest setup to work with a previous instance of an application but in the new version the POST was empty (no data sent); I knew the server on the other end was working fine (same code, but new hosting/URL) so I knew it couldn't be that.

After playing with it for a bit I remembered that the old URL was submission.php, but this time it was it's own folder (so just /submission/), adding index.php to the end of my new URL magically made things work again; so I guess it just didn't like not having a file at the end of the URL.

tl;dr - make sure your submission URL's end with a file name (ie: index.php or similar)

nbsp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜