为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

ibeautiful 2019-04-08 11:18:06
如题啊该怎么弄?之前用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了该怎么弄
查看完整描述

2 回答

?
湖上湖

TA贡献2003条经验 获得超2个赞

AF提供了form请求的api
-(NSMutableURLRequest*)multipartFormRequestWithMethod:(NSString*)method
URLString:(NSString*)URLString
parameters:(NSDictionary*)parameters
constructingBodyWithBlock:(void(^)(idformData))block
                            
查看完整回答
反对 回复 2019-04-08
  • 2 回答
  • 0 关注
  • 554 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信