httpurlconnection openConnection返回false

时间:2013-09-26 08:06:35

标签: android

我用c#编写的Web服务及其工作正常 当我从我的Android代码中请求此服务时,它给我连接问题 我的代码看起来像这样

 URL url;
try {
        url = new URL("http://192.168.1.35/Audio.ashx");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();

当我调试连接参数“connected = false”

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

尝试从中获取输入流,然后可以获取数据: -

 URL url;
    try {
        url = new URL("http://www.mysite.se/index.asp?data=99");

        HttpURLConnection urlConnection = (HttpURLConnection) url
                .openConnection();

        InputStream in = urlConnection.getInputStream();

        InputStreamReader isw = new InputStreamReader(in);

        int data = isw.read();
        while (data != -1) {
            char current = (char) data;
            data = isw.read();
            System.out.print(current);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

答案 1 :(得分:0)

的AndroidManifest.xml

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