2011-04-09 67 views
1

我想在Android模擬器上寫一個java代碼,將發送一個字符串到C#編寫的Web服務。試圖從Android模擬器發送一個字符串到一個web服務

的Android代碼:

 HttpPost httppost = new HttpPost("http://192.168.2.1:53811/WinnerSite/WebService.asm/MyMethod 


    try { 
     // Add your data 
     List nameValuePairs = new ArrayList(2); 
     nameValuePairs.add(new BasicNameValuePair("json", name)); 
     // nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); 
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

     // Execute HTTP Post Request 
     HttpResponse response = httpclient.execute(httppost); 

也試過:

 
    HttpPost httppost = new HttpPost("http://192.168.2.1:53811/WinnerSite/WebService.asm/MyMethod

web服務是在同一臺機器作爲仿真器上。 MyMethod可通過以下方式訪問:

 
http://localhost:53811/WinnerSite/WebService.asmx/MyMethod 

是否有某種想法? 代碼在「httpclient.execute(httppost);」上退出;線 月食顯示: "ActivityThread.prefo Source not found."

我已經解決了persmission問題(添加註釋到emolator的XML)

感謝,

+0

我不清楚你的問題是什麼。運行應用程序或構建應用程序時出現某種錯誤? 「日食顯示...」非常模糊。你能發佈完整的錯誤,並解釋你在什麼階段看到它? – 2011-04-09 08:42:03

回答

1

當你想使用網絡,你應該添加網絡訪問您的AndroidManifest.xml中的權限。

你的問題似乎很複雜。分別檢查您的客戶端應用程序和Web服務,以確保它們都是正確的。

您的編碼發佈似乎是正確的。但是你的錯誤信息「ActivityThread.prefo Source not found。」太弱...請提供更多信息。

相關問題