iOS stringWithContentsOfURL给出了HTML错误

时间:2013-09-06 06:50:46

标签: iphone ios ipad ios6

我正在尝试使用SBJSon解析Google Maps api但在解析之前我使用下面的代码时会在HTML中出现Access Denied错误,只有当我在{{1如果我在模拟器中运行相同的..它给了我google maps api string ..应该是设备运行的错误。

Device

错误

NSString *String = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; NSLog(@"string %@",string);

完整的Html错误类似于 Setting Proxy Username & password using Objective-C - iPhone

1 个答案:

答案 0 :(得分:0)

您的设备所连接的网络不允许访问该网址。由于您可以从MAC访问URL,因此请将设备连接到与MAC相同的网络。它应该工作。

替代解决方案,首先从设备Safari浏览器访问一些URL。如果要求身份验证,请提供正确的用户名和密码。连接后,请勿关闭选项卡或Safari应用程序。运行您的应用程序,URL现在应该可以运行。


修改

如果您仍然面临身份验证问题,可能最好实现实现NSURLConnectionDelegate的异步下载程序。在方法

中提供身份验证参数
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;

您使用的stringWithContentsOfURL:encoding:error: API不会给您太多灵活性。

希望有所帮助!