-(void)postData

{

    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.abc.com"]];

    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];

    [request setValue:@"application/json" forHTTPHeaderField:@"Content-type"];

    

    request.HTTPMethod = @"POST";

    NSString* requestBodyString = @"{\"key1\":\"value1\", \"key2\":\"value2\"}";

    NSData* data = [requestBodyString dataUsingEncoding:NSUTF8StringEncoding];

    request.HTTPBody = data;

    

    NSOperationQueue* backgroundQueue = [[NSOperationQueue alloc]init];

    [NSURLConnection sendAsynchronousRequest:request queue:backgroundQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

        if (connectionError) {

            NSLog(@"post data request error!");

        }

    }];

}

posted on 2015-03-24 14:45  ximenchuixie  阅读(505)  评论(0编辑  收藏  举报