【问题标题】:How to use Ignition HTTP classes to make Get request?如何使用 Ignition HTTP 类发出 Get 请求?
【发布时间】:2013-02-12 02:28:59
【问题描述】:

[Ignition][1] 的文档相当稀少。我正在查看 HTTP 类的文档,例如 link here,但我很困惑。

我当前的代码看起来像这样(经过清理的版本):

client = AndroidHttpClient.newInstance(MyConstants.USER_AGENT);
String url = SaveConstants.MY_URL;
url += "?" + MyConstants.MY_PARAMETER + "=" + parameterValue;
HttpGet request = new HttpGet(url);
InputStream contentStream = null;
try {
    HttpContext httpContext = new BasicHttpContext();
    HttpResponse response = client.execute(request, httpContext);
    contentStream = response.getEntity().getContent();
    String content = Util.inputStreamToString(contentStream);
}

如何更改它以使用 Ignition 类?我有两个问题:

  1. 我看不到如何初始化或使用 IgnatedHttpRequest。似乎没有任何构造函数和文档可以解释此类的使用。
  2. IgnatedHttpRequest 可以使用 GET 请求,还是只使用 POST?

【问题讨论】:

    标签: android


    【解决方案1】:

    使用 IgnitedHttp 类:link

    所以,

    new IgnitedHttp(context).get("http://www.example.com") 
    

    将返回您可以调用 send() 方法的 IgnitedHttpRequest 对象。

    有关 IgnitedHttpRequest 的更多信息,请参阅:link

    此 send() 将返回一个 IgnitedHttpResponse 对象,您可以调用该对象 getResponseBodyAsString()。

    有关 IgnatedHttpResponse 的更多信息,请参阅: link

    总之,

    new IgnitedHttp(context).get(url).send().getResponseBodyAsString() 
    

    是您第一个问题的答案。你的第二个问题的答案是 IgnitedHttp 也有帖子、放置等方法。

    这里有很多你可能想做的事情的示例活动:https://github.com/mttkay/ignition/blob/master/ignition-support/ignition-support-samples/src/com/github/ignition/samples/support/IgnitedHttpSampleActivity.java

    享受使用我找到的最好的代码。

    【讨论】:

    • 太好了,我现在开始喜欢 Ignition 课程了!很好的答案,原谅上帝!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    • 2014-08-15
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    相关资源
    最近更新 更多