Form Data Request using NSURLConnection in iOS

前端 未结 5 624
轻奢々
轻奢々 2020-12-15 01:04

I want to make http form post using NSURLConnection in iOS. I have two form fields and one file upload option in an HTML form. When I am doing same thing using NSURLCo

5条回答
  •  长情又很酷
    2020-12-15 01:16

    You have several

    rn
    

    in the end of your strings. All of them should be

    \r\n
    

    More precisely it should be:

    [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"file\"; filename=\"myphoto.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    

提交回复
热议问题