我有以下详细信息,用于从服务器获取数据。methodIdentifier 和 Web 服务名称有什么用?
{"zip":"12345","methodIdentifier":"s_dealer"}
url:- http://xxxxxxxxxxxxxxx.com/api.php
method: post
web service name: s_dealer
response : {"success":"0","dealer":[info...]}
我不知道如何使用 url发送邮政编码“12345” 。请指引我正确的方向。我使用以下。
-(void)IconClicked:(NSString *)zipNumber
{
NSString *post = [NSString stringWithFormat:@"&zipNumber=%@",zipNumber];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://xxxxxxxxxxxxxxxxxxx.com/api.php"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(conn)
{
NSLog(@"Connection Successful");
}
else
{
NSLog(@"Connection could not be made");
}
receivedData = [[NSMutableData alloc]init];
}
当我在控制台中打印响应时:\“字符串意外结束\”