首页 文章

尝试将字符串从Android模拟器发送到Web服务

提问于
浏览
1

我正在尝试在Android模拟器上编写一个java代码,该代码将字符串发送到c#中写入的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."

我已经解决了一个延迟问题(在emolator的xml中添加了一个注释)

谢谢,

1 回答

  • 1

    如果要使用网络,则应在AndroidManifest.xml中添加网络访问权限 .

    你的问题似乎很复杂 . 分别检查您的客户端应用程序和Web服务,以确保它们都正确 .

    您发布的代码似乎是正确的 . 但是您的错误消息“未找到ActivityThread.prefo Source . ”太弱了......请提供更多信息 .

相关问题