我正在从xcode 4调用用.net编写的webservice。输出是一个json字符串。当使用静态IP地址使用url进行调用时,它会给出错误。HTTP错误404.0 - 未找到。但是在localhost中调用相同的url时有效。代码如下
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url=[NSURLURLWithString:@"http:// static ip address where serviceis located(169.254.216.8)/restGroceryService/WebService/insertList?prods=apples,bananas,milk"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *pageSource = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"page source%@",pageSource);
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSArray *array = [json objectForKey:@"result"];
NSDictionary *store = [array objectAtIndex:0];
NSNumber *storeId = [store objectForKey:@"storeId"];
NSNumber *total = [store objectForKey:@"TOTAL"];
self.priceTextField.text =[total stringValue];
NSString *storeName = [store objectForKey:@"storeName"];
self.storNameTextField.text = storeName;
}