1

我制作了一个接受 xml 数据的应用程序,但是当我发送对该资源的查询时,看起来没有连接。我添加了 android 互联网权限并在浏览器中有网络,但在我的应用程序中没有任何连接。

这是代码

    受保护的字符串发送请求(字符串 urlAdr,ArrayList postVars){


        字符串数据=extractPairValuesToString(postVars);
        urlAdr+=数据;//发送url中的所有变量,而不是来自请求属性
        字符串 xmlResponse=null;
        HttpURLConnection con = null;
        网址网址;


        尝试 {
            url = 新 URL(urlAdr);
            con = (HttpURLConnection) url.openConnection();
            //con.setReadTimeout(10000 /* 毫秒 */);
            //con.setConnectTimeout(15000 /* 毫秒 */);
            con.setRequestMethod("POST");
            con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");        
            con.setRequestProperty("Connection", "Keep-Alive");
            con.setRequestProperty("Content-Length", ""+Integer.toString(data.getBytes().length));
            con.setDoInput(true);
            con.setDoOutput(true);


        }catch (IOException e) {

            setErrorStatus(e.getMessage());
        }
    }
4

1 回答 1

3

很多时候,清单都丢失了:

<uses-permission android:name="android.permission.INTERNET"/>  

见这里:http: //developer.android.com/resources/tutorials/views/hello-webview.html

于 2011-12-24T13:29:56.757 回答