2013-09-26 77 views
0

我已經寫在C#中的Web服務和它的工作好 當我問從我的Android代碼,這項服務把它給我的問題與連接 我的代碼看起來像這樣HttpURLConnection類的openConnection返回false

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

時我調試它的連接參數「connected = false」

任何建議?

回答

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(); 
    } 
+0

其實我環節的工作很好,當我問它手動瀏覽器手動,但不是從代碼 –

+2

最後我找到了答案,openConnection()後;我們應該寫connection.connect();並且一切都會好:) –

0

AndroidManifest.xml中

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

+0

我已經添加了,沒有結果:( –

+0

嘗試tcpdump + wireshard,確定是否有網絡錯誤。 – afpro