NSString *urlString = [NSString stringWithFormat:@"http://10.130.171.113:81/WAPService/WAPJsonService.ashx?serviceCode=00000045"];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

[request setURL:[NSURL URLWithString:urlString]];

[request setHTTPMethod:@"POST"];

//set headers

NSString *contentType = [NSString stringWithFormat:@"text/xml"];

[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

//create the body

NSMutableData *postBody = [NSMutableData data];

[postBody appendData:[[NSString stringWithFormat:@"{'Paramters':['2020101001360']}"] dataUsingEncoding:NSUTF8StringEncoding]];

//[postBody appendData:[[NSString stringWithFormat:@"<yourcode/>"] dataUsingEncoding:NSUTF8StringEncoding]];

//[postBody appendData:[[NSString stringWithFormat:@"</xml>"] dataUsingEncoding:NSUTF8StringEncoding]];

//postBody

[request setHTTPBody:postBody];

//get response

NSHTTPURLResponse* urlResponse = nil;  

NSError *error = [[NSError alloc] init];  

NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];  

NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSDictionary *dictionary=[result JSONValue]; 

dictionary=[dictionary objectForKey:@"Result"];

NSLog(@"产品编码是:%@",[dictionary objectForKey:@"ProductNo"]);

NSLog(@"Response Code: %d", [urlResponse statusCode]);

if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {

NSLog(@"Response: %@", result );

//here you get the response

}

posted on 2011-04-11 15:16  kitea  阅读(517)  评论(0)    收藏  举报