前端iOS向后端Django传输多模块数据
HTTP POST请求,发送multipart/form-data
为了能够理解在iOS端对post数据所做的包装,可以先阅读这样一篇文章: HTTP请求基本介绍
阅读完上面这篇文章,就可以开始进行编写
//
// EZHttpRequest.m
//
// Created by apple on 14-3-6.
// Copyright (c) 2014年 apple. All rights reserved.
//
#import "EZHttpRequest.h"
#define boundary @"---------------------------14737809831466499882746641449"
#define file_key @"docfile"
@implementation EZHttpRequest
+(NSData *)post:(NSArray *)content toURL:(NSURL *)post_url{
/*---------------------form of content data---------------------
1,Http header filed
Content-Type:multipart/form-data; boundary=@""
Content-Length:
2,content:
(1){boundary}
(2)Content-Disposition:form-data;name=@""
*(3)If data is not string,add:Content-Type:
(4)data
3,every line should end with '\r\n'
---------------------form of content data---------------------*/
//create url request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[