當前位置:成語大全網 - 書法字典 - iosafn如何用post上傳json數據

iosafn如何用post上傳json數據

代碼如下:

AFHTTPRequestOperationManager * manager =[AFHTTPRequestOperationManager manager];

//聲明返回的結果是json類型。

manager . response serializer =[afjsonresponse serializer serializer];

//聲明請求的數據是json類型。

manager . request serializer =[AFJSONRequestSerializer serializer];

//如果消息接受類型不壹致,請替換壹致的text/html或其他。

manager . responseserializer . acceptable content types =[ns set setWithObject:@ " text/html "];

//傳入的參數

ns dictionary * parameters = @ { @ " 1 ":@ " XXXX "," 2":@"XXXX "," 3 ":@ " XXXXX " };

//您的接口地址

ns string * URL = @ " http://";

//發送請求

[經理發布:url參數:參數success:^(afhttprequestoperation *操作,id響應對象){

NSLog(@"JSON: %@ ",response object);

} failure:^(afhttprequestoperation *操作,nserror *錯誤){

NSLog(@“錯誤:%@”,錯誤);