PhoneGap iOS应用中的401未经授权的响应 [英] 401 Unauthorized Response In PhoneGap iOS App

查看:76
本文介绍了PhoneGap iOS应用中的401未经授权的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Xcode 4.3中运行iPhone 5.0模拟器.已安装PhoneGap 1.4.1.我有以下index.html文件,类似于 http://wiki.phonegap.com/w/page/42450600/PhoneGap%20Ajax%20Sample :

I'm running the iPhone 5.0 Simulator within Xcode 4.3. PhoneGap 1.4.1 is installed. I have the following index.html file, similar to the example at http://wiki.phonegap.com/w/page/42450600/PhoneGap%20Ajax%20Sample:

<!DOCTYPE html>
<html>    
    <head>        
        <title>PhoneGap Ajax Sample</title>        
        <script type="text/javascript" src="phonegap-1.4.1.js"></script>        
        <script>
            function appReady(){                                
                var ajax = new XMLHttpRequest();                
                ajax.open("GET","http://search.twitter.com/search.json?q=bacon",true);                
                ajax.onreadystatechange=function(){
                    alert(ajax.readyState);
                    alert(ajax.status);
                    if(ajax.readyState==4 && (ajax.status==200)){
                        document.getElementById('main').innerHTML = ajax.responseText;
                    }
                }               
                ajax.send();                
            }            
            document.addEventListener("deviceready", appReady, false);            
            </script>        
    </head>    
    <body onload="onBodyLoad()">        
        <div id="main">            
            <p>before load</p>            
        </div        
    </body>    
</html>

在进行了调试alert()调用后,我看到显示2,然后401,然后3,然后401,然后4,然后401的对话框.

With the debugging alert() calls in place, I see dialogs showing 2, then 401, then 3, then 401, then 4, then 401.

401对话框当然表明该请求是未授权的.我尝试过除Twitter以外的其他网站均未成功.我可以在模拟器上使用Safari浏览网络.当我在Windows上的Eclipse中创建PhoneGap Android项目时,以上代码将在Droid 2上按预期运行.我是iOS和PhoneGap开发的新手,所以我可能忽略了一些简单的事情.有什么想法吗?

The 401 dialogs indicate, of course, that the request is unauthorized. I've tried websites other than twitter with no success. I am able to use Safari on the simulator to browse the web. The code above runs as expected on my Droid 2 when I create a PhoneGap Android project in Eclipse on Windows. I'm new to iOS and PhoneGap development, so I may be overlooking something simple. Any ideas?

顺便说一句,关于此,SO上还有一个或两个其他问题,但是设置不同,例如一个使用了OAuth.

BTW, there are one or two other questions on SO about this, but the setups are different, such as one used OAuth.

推荐答案

我只需要将search.twitter.com添加到PhoneGap.plist/ExternalHosts.

I just needed to add search.twitter.com to PhoneGap.plist/ExternalHosts.

这篇关于PhoneGap iOS应用中的401未经授权的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆