我在我的iOS应用程序中使用openweathermap。
下面是我的网址,这是我要求获取的是否信息。
http://api.openweathermap.org/data/2.5/weather?lat=21.282778&lon=-157.829444&APPID=MYAPPID&lang=en-US
当在浏览器中打开这个url时,我得到了正确的响应。
但是当我从我的iOS应用程序调用网络服务时,我没有得到响应。我得到了以下错误:
{
cod = 401;
message = "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info.";
}我从这个网址:在开放式皮革上创建API密钥创建了API键
发布于 2016-03-08 12:37:08
NSURL *URL = [NSURL URLWithString:@"http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a&lang=en-US"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
NSError* errorObj;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:&errorObj];
NSLog(@" response is %@",json);
}];
[task resume];你的应用程序id应该是有效的。我已经为演示用硬编码了url。
https://stackoverflow.com/questions/35866624
复制相似问题