【问题标题】:Trying to send a string from an Android emulator to a webservice尝试将字符串从 Android 模拟器发送到 Web 服务
【发布时间】:2011-08-02 00:08:11
【问题描述】:

我正在尝试在 Android 模拟器上编写一个 java 代码,它将一个字符串发送到一个用 c# 编写的 Web 服务。

安卓代码:

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


    尝试 {
        // 添加你的数据
        列表名称ValuePairs = new ArrayList(2);
        nameValuePairs.add(new BasicNameValuePair("json", name));
      // nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev 很酷!"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // 执行 HTTP Post 请求
        HttpResponse 响应 = httpclient.execute(httppost);

也试过了:

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

网络服务与模拟器在同一台机器上。 MyMethod 可通过以下方式访问:

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

有人有想法吗? 代码在“httpclient.execute(httppost);”上退出线 日食显示: "ActivityThread.prefo Source not found."

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

谢谢,

【问题讨论】:

  • 我不清楚你的问题是什么。您在运行应用程序或构建应用程序时遇到某种错误? “日食显示……”非常模糊。您能否发布完整的错误并解释您在哪个阶段看到它?

标签: android eclipse


【解决方案1】:

当你想使用网络时,你应该在你的AndroidManifest.xml中添加网络访问权限。

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

您发布的代码似乎是正确的。但是你的错误信息“ActivityThread.prefo Source not found”。太弱了...请提供更多信息。

【讨论】:

    猜你喜欢
    • 2012-05-21
    • 2017-08-03
    • 2012-05-03
    • 2011-10-26
    • 2015-10-20
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 2011-09-16
    相关资源
    最近更新 更多