【问题标题】:How do I call Web Service written in Python from Android app如何从 Android 应用程序调用用 Python 编写的 Web 服务
【发布时间】:2014-02-27 12:39:12
【问题描述】:

Here is my web service code

我可以在我的浏览器中使用http://sheltered-taiga-3258.herokuapp.com/toi/<input parameters> 调用它我正在从安卓设备上的用户那里收集输入参数。显然,Web 服务返回一个 JSON 数据,我需要在 android 应用程序的客户端显示该数据。我浏览了许多关于 android 和 web 服务的帖子和教程,但没有成功,因为很多人都有 PHP 中的 POST 请求和服务的 web 服务示例。我想为 GET 做这件事,服务在烧瓶中。

请帮忙谢谢。

编辑:

我正在使用 HttpGet 对象调用 Web 服务,并将我的 URL 作为参数传递给它。

HttpGet httpget = new HttpGet(myURL);

我将 myURL 构造为

EditText inputString = (EditText) findViewById(R.id.serverText);
String appendString =URLEncoder.encode(inputString.getText().toString(), "UTF-8") ;
private final HttpClient Client = new DefaultHttpClient();
String myURL = "http://sheltered-taiga-3258.herokuapp.com/toi/" + appendString;

这里我的网址是 http://sheltered-taiga-3258.herokuapp.com/toi/hc+stays+toll+collection 但我想要这种方式

http://sheltered-taiga-3258.herokuapp.com/toi/HC%20stays%20toll%20collection%20in%20kolhapur%20city

我知道有一些 url 编码问题,但不知道如何解决。

【问题讨论】:

  • 检查123给出的答案。
  • @ABDC 感谢这位似乎正在工作的人...将尽快尝试并在此处发布。

标签: android url url-encoding flask-restful android-webservice


【解决方案1】:

以下是我的问题的解决方案可能不是建议的标准方法,但让我摆脱了问题:

String appendString = (inputString.getText().toString()).replace(" ", "%20") ;//here %20 is encoding for space
String myURL = "http://sheltered-taiga-3258.herokuapp.com/toi/" + appendString;

这给了我这个:

http://sheltered-taiga-3258.herokuapp.com/toi/HC%20stays%20toll%20collection%20in%20kolhapur%20city

而不是这个

http://sheltered-taiga-3258.herokuapp.com/toi/hc+stays+toll+collection

如果我找到了做这件事的真实方法,我一定会在此处发布并标记为答案

【讨论】:

  • 这种做法真的很糟糕,请参考stackoverflow.com/a/3286128/1008278
  • @VenomVendor 是的,我当然知道这不是真正的方法......但以某种方式解决了我的问题,我将寻求进一步即兴发挥......但如果你检查我的问题,那么你会看到我首先尝试使用URLEncoder.encode("URLSTRING","UTF-8") 以正常真实的方式进行操作并给了我不好的结果......
猜你喜欢
  • 2018-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-13
  • 1970-01-01
  • 2016-12-20
相关资源
最近更新 更多