A. Uploading JSON1. Idea: You must use the Post method to upload a large number of JSON data set request header: Set Content-type set the request body, JSON is actually equivalent to the dictionary, You can use Nsdictionarynsjsonserialization to convert the dictionary data into JSON binary 2. Implement
1 //2 //VIEWCONTROLLER.M3 //Postjsondemo4 //5 //Created by Hellovoidworld on 15/1/28.6 //Copyright (c) 2015 Hellovoidworld. All rights reserved.7 //8 9 #import "ViewController.h"Ten One @interfaceViewcontroller () A-(ibaction) Postjson; - - @end the - @implementationViewcontroller - -- (void) Viewdidload { + [Super Viewdidload]; - //additional setup after loading the view, typically from a nib. + } A at-(ibaction) Postjson { - //1. Create a request -Nsurl *url = [Nsurl urlwithstring:@"Http://192.168.0.21:8080/MyTestServer/acceptJson"]; -Nsmutableurlrequest *request =[Nsmutableurlrequest Requestwithurl:url]; - //set up post send -Request. HttpMethod =@"POST"; in - //2. Set the request header to[Request SetValue:@"Application/json"Forhttpheaderfield:@"Content-type"]; + - //3. Set the request body theNsdictionary *json = @{@"name":@"Tom", * @" Age":@" +"}; $Request. Httpbody =[nsjsonserialization Datawithjsonobject:json options:nsjsonwritingprettyprinted Error:nil];Panax Notoginseng - the //4. Sending the request +[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, NSData *data, Nserror *connectionerror) { ANSLog (@"%@", [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves Error:nil]); the }]; + - } $ @end
B. Multi-valued parameters1. Concept a parameter name corresponds to multiple parameter values HTTP://LOCALHOST:8080/MYTESTSERVER/UPLOAD?TYPE=AAA&TYPE=BBB&TYPE=CCC so that the server receives an array
[IOS Multithreading & Networking-2.6]-use post to upload JSON data & multivalued parameters