每個人遇到后臺的需求不一樣,我只能寫出自己目前遇到的需求和做法,我的后臺是需要一個Json的key,對應一個字符串類型的字典,后臺要求的是帶雙引號和冒號的字典,所以就拼接了一下
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; // 發送post請求// manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"]; // manager.requestSerializer=[AFHTTPRequestSerializer serializer]; NSDictionary *json = [NSDictionary dictionary]; NSString *str = [NSString stringWithFormat:@"{/"city/":/"%@/",/"country/":/"%@/",/"headimgurl/":/"%@/",/"language/":/"%@/",/"openid/":/"%@/",/"province/":/"%@/",/"sex/":%@,/"unionid/":/"%@/",/"userName/":/"%@/"}",self.userInfoDict[@"city"],self.userInfoDict[@"country"],self.userInfoDict[@"headimgurl"],self.userInfoDict[@"language"],self.userInfoDict[@"openid"],self.userInfoDict[@"province"],self.userInfoDict[@"sex"],self.userInfoDict[@"unionid"],self.userInfoDict[@"nickname"]]; json = @{// @"city":self.userInfoDict[@"city"],// @"country":self.userInfoDict[@"country"],// @"headimgurl":self.userInfoDict[@"headimgurl"],// @"language":self.userInfoDict[@"language"],// @"openid":self.userInfoDict[@"openid"],// @"province":self.userInfoDict[@"province"],// @"sex":self.userInfoDict[@"sex"],// @"unionid":self.userInfoDict[@"unionid"],// @"userName":self.userInfoDict[@"nickname"], @"json":str,// @"json":@"json" }; NSLog(@"post調試%@",json); NSString *URLStr = @"http://10.62.16.247:8080/LoginServlet.bmh"; [manager POST:URLStr parameters:json progress:^(NSProgress * _Nonnull uploadProgress) { } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSString *str = responseObject; NSLog(@"post回調====%@",str); NSLog(@"post成功"); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"post失敗"); }];
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答