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

如题啊

该怎么弄?

之前用asi的时候是这样的

NSDictionary *sinaDBDictionary = [sinaDBArray objectAtIndex:0];

NSString *accessTokenKey = [sinaDBDictionary objectForKey:@"AccessTokenKey"];

NSString *wbUid = [sinaDBDictionary objectForKey:@"UserIDKey"];

NSString *boundary = @"14745591349540787582088777204";

//设置请求体中内容

NSMutableString *bodyString = [NSMutableString string];

[bodyString appendFormat:@"-----------------------------%@\r\n", boundary];

[bodyString appendString:@"Content-Disposition: form-data; name=\"accessToken\"\r\n"];

[bodyString appendString:@"\r\n"];

[bodyString appendString:accessTokenKey];

[bodyString appendString:@"\r\n"];

[bodyString appendFormat:@"-----------------------------%@\r\n", boundary];

[bodyString appendString:@"Content-Disposition: form-data; name=\"wbUid\"\r\n"];

[bodyString appendString:@"\r\n"];

[bodyString appendString:wbUid];

[bodyString appendString:@"\r\n"];

[bodyString appendFormat:@"-----------------------------%@--\r\n",boundary];

NSMutableData *bodyData = [[NSMutableData alloc]initWithLength:0];

NSData *bodyStringData = [bodyString dataUsingEncoding:NSUTF8StringEncoding];

[bodyData appendData:bodyStringData];

NSString *len = [NSString stringWithFormat:@"%d",[bodyData length]];

NSString *s = [NSString stringWithFormat:@"multipart/form-data; boundary=---------------------------%@", boundary];

NSString *url = @"屏蔽屏蔽屏蔽屏蔽掉";

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL: [NSURL URLWithString: url]];

request.defaultResponseEncoding = NSUTF8StringEncoding;

request.useCookiePersistence = YES;

[request setRequestMethod:@"POST"];

[request addRequestHeader:@"Content-Type" value:s];

[request addRequestHeader:@"Content-Length" value:len];

[request setPostBody:bodyData];

[request startSynchronous];

NSError *error = request.error;

if (!error) {

// NSLog(@"%@",[request responseString]);

}else{

// NSLog(@"%@",[[request error]localizedDescription]);

}

真的是好复杂啊

然后现在要转为afn了 该怎么弄

你可能感兴趣的:(afn请求修改服务器数据)