Created
January 13, 2016 04:37
-
-
Save ondev/7e225708db272076cf87 to your computer and use it in GitHub Desktop.
iOS mutilpart post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set content type to be form data | |
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"]; | |
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; | |
[request addValue:contentType forHTTPHeaderField:@"Content-Type"]; | |
// Set content type to be form data | |
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"]; | |
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; | |
[request addValue:contentType forHTTPHeaderField:@"Content-Type"]; | |
// Set up web request with HTTP post headers for 1 form field which is the image | |
NSMutableData *body = [NSMutableData data]; | |
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding: NSUTF8StringEncoding]]; | |
[body appendData: [NSData dataWithData:data]]; | |
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding: NSUTF8StringEncoding]]; | |
// Set the body | |
[request setHTTPBody: body]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment