发送 json 数据

-(void)testJson{
    
    SBJSON *jsonWriter = [[SBJSON new] autorelease];
    
    NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                                                      @"10",@"age",@"wsx",@"name", nil], nil];
    NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
    
    NSMutableData *postBody = [NSMutableData data];
    [postBody appendData:[[NSString stringWithFormat:actionLinksStr] dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSLog(@"~~~~~~~~~ %@", actionLinksStr);
    
    NSURL *pUrl = [[NSURL alloc] initWithString:@"http://IP:8080/DataReportServer/reportData"];
    NSMutableURLRequest *pRequest = [NSMutableURLRequest requestWithURL:pUrl cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
    [pRequest setHTTPMethod:@"POST"];
    [pRequest setValue:@"close" forHTTPHeaderField:@"Connection"];
    [pRequest setValue:@"application/vnd.syncml+wbxml" forHTTPHeaderField:@"Content-Type"];
    [pRequest setHTTPBody:postBody];
    [NSURLConnection connectionWithRequest:pRequest delegate:self];
    [pUrl release];
}

posted @ 2013-03-28 16:59  李伯波  阅读(145)  评论(0编辑  收藏  举报