iPhone ASIFormDataRequest with multipart/form-data

2019-05-24 21:06发布

问题:

as I have read in the ASI Documentation, its writen: "Data is posted in 'application/x-www-form-urlencoded' format, or 'multipart/form-data' format when uploading binary data or files."

That's exactly my Problem. I am sending just a String to a server, but the server just accepts 'multipart/form-data' and as I just send a String, the ASI Framework creates a POST request with 'application/x-www-form-urlencoded' format automatically, cause I am not sending any binary data or file. Result: the server does not accept my POST request.

How could I solve this problem?

Thanks in advance for helping.

回答1:

You could set the format manually:

[request setPostFormat:ASIMultipartFormDataPostFormat];


回答2:

I've just solved this problem in a very ugly way: I've changed the ASIFormDataRequest implementation on line 200:

if ([self postFormat] == ASIURLEncodedPostFormat) {
    [self buildMultipartFormDataPostBody];  //NEW LINE  
    //[self buildURLEncodedPostBody];  ORIGINAL LINE
} else {
    [self buildMultipartFormDataPostBody];
}

I would be glad to hear any other suggestion!