2011-04-09 70 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。”太弱...请提供更多信息。

相关问题