服务器那边的请求的content-tpye是multipart/form-data,我要怎么发送数据去请求?用afnetworking

如题啊
该怎么弄?
之前用asi的时候是这样的
NSDictionary*sinaDBDictionary=[sinaDBArrayobjectAtIndex:0];
NSString*accessTokenKey=[sinaDBDictionaryobjectForKey:@"AccessTokenKey"];
NSString*wbUid=[sinaDBDictionaryobjectForKey:@"UserIDKey"];
NSString*boundary=@"14745591349540787582088777204";
//设置请求体中内容
NSMutableString*bodyString=[NSMutableStringstring];
[bodyStringappendFormat:@"-----------------------------%@\r\n",boundary];
[bodyStringappendString:@"Content-Disposition:form-data;name=\"accessToken\"\r\n"];
[bodyStringappendString:@"\r\n"];
[bodyStringappendString:accessTokenKey];
[bodyStringappendString:@"\r\n"];
[bodyStringappendFormat:@"-----------------------------%@\r\n",boundary];
[bodyStringappendString:@"Content-Disposition:form-data;name=\"wbUid\"\r\n"];
[bodyStringappendString:@"\r\n"];
[bodyStringappendString:wbUid];
[bodyStringappendString:@"\r\n"];
[bodyStringappendFormat:@"-----------------------------%@--\r\n",boundary];
NSMutableData*bodyData=[[NSMutableDataalloc]initWithLength:0];
NSData*bodyStringData=[bodyStringdataUsingEncoding:NSUTF8StringEncoding];
[bodyDataappendData:bodyStringData];
NSString*len=[NSStringstringWithFormat:@"%d",[bodyDatalength]];
NSString*s=[NSStringstringWithFormat:@"multipart/form-data;boundary=---------------------------%@",boundary];
NSString*url=@"屏蔽屏蔽屏蔽屏蔽掉";
ASIFormDataRequest*request=[ASIFormDataRequestrequestWithURL:[NSURLURLWithString:url]];
request.defaultResponseEncoding=NSUTF8StringEncoding;
request.useCookiePersistence=YES;
[requestsetRequestMethod:@"POST"];
[requestaddRequestHeader:@"Content-Type"value:s];
[requestaddRequestHeader:@"Content-Length"value:len];
[requestsetPostBody:bodyData];
[requeststartSynchronous];
NSError*error=request.error;
if(!error){
//NSLog(@"%@",[requestresponseString]);
}else{
//NSLog(@"%@",[[requesterror]localizedDescription]);
}
真的是好复杂啊
然后现在要转为afn了该怎么弄
ibeautiful
浏览 555回答 2
2回答

湖上湖

AF提供了form请求的api-(NSMutableURLRequest*)multipartFormRequestWithMethod:(NSString*)methodURLString:(NSString*)URLStringparameters:(NSDictionary*)parametersconstructingBodyWithBlock:(void(^)(idformData))block
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript