當前位置:股票大全官網 - 財經資訊 - IOS要求後臺主體的格式是通過AFN的formData相關代碼。

IOS要求後臺主體的格式是通過AFN的formData相關代碼。

-(void)setFormData:(ns dictionary *)formData with request:(nsmutableulrequest *)request {

靜電?ns string * boundary data = @“12436041281943726692693274280“;

//設置請求正文中的內容

NSMutableString * body string =【【NSMutableString alloc】init】;

?for(int I =【【formDataallKeys】count】-1;我& gt=0;我- ) {

ns string * key =【formDataallKeys】【I】;

ns string * value =【formDataallValues】【I】;

?if(【keyisEqualToString:@“access token“】){

value =【valuesubstringindex:32】;

}

【bodyStringappendFormat:@“-% @ \ r \ n content-Disposition:form-data;name = \“% @ \“\ r \ n \ r \ n % @ \ r \ n“,boundaryData,key,value】;

}

【bodyStringappendFormat:@“-% @-\ r \ n“,boundary data】;

NSMutableData * body data =【【NSMutableData alloc】initWithLength:0】;

ns data * bodyStringData =【bodystringdatausing encoding:nsu TF 8 string encoding】;

【bodyDataappendData:bodyStringData】;

ns string * contentLength =【NSStringstringWithFormat:@“% d“,【body datalength】】;

ns string * content type =【ns string string with format:@“multipart/form-data;boundary= - %@“,boundary data】;

【requestsetValue:contentTypeforHTTPHeaderField:@“Content-Type“】;

【requestsetValue:contentLengthforHTTPHeaderField:@“Content-Length“】;

【requestsetHTTPBody:body data】;

【requestsetHTTPMethod:@“POST“】;

}