Lwtviewcontroller.m
////LWTVIEWCONTROLLER.M//Network Programming Exercises--Post-json data////Created by Apple on 14-7-2.//Copyright (c) 2014 LWT. All rights reserved.//#import "LWTViewController.h"@interfaceLwtviewcontroller ()@end@implementationLwtviewcontroller- (void) viewdidload{[Super Viewdidload]; //additional setup after loading the view, typically from a nib.}- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event{Nsurl*url = [Nsurl urlwithstring:@"Http://192.168.1.24:8080/MJServer/resources/order"]; Nsmutableurlrequest*request =[Nsmutableurlrequest Requestwithurl:url]; Request. HttpMethod=@"POST"; [Request SetValue:@"Application/json"Forhttpheaderfield:@"Content-type"]; Nsdictionary*json = @{ @"order_id":@"123", @"user_id":@"456", @" Shop":@"Toll" }; NSData*data =[nsjsonserialization Datawithjsonobject:json options:nsjsonwritingprettyprinted Error:nil]; Request. Httpbody=data; [Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] CompletionHandler:^ (Nsurlresponse *response, NSData *data, Nserror *connectionerror) {NSLog (@"%d", data.length); }];}@endView Code