[IOS Multithreading & Networking-2.6]-use post to upload JSON data & multivalued parameters

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.