本文介绍了如何使用HTTP点火班,使Get请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档[点火] [1] 是相当稀少。我在看的HTTP类的文档,如这里

因此​​,

 新IgnitedHttp(上下文)获得(http://www.example.com)

将返回IgnitedHtt prequest对象,你可以调用的send()方法。

请参阅有关IgnitedHtt prequest更多的信息:<一href=\"http://mttkay.github.com/ignition-docs/ignition-support/apidocs/com/github/ignition/support/http/IgnitedHtt$p$pquest.html\"相对=nofollow>链接

本的send()将返回一个IgnitedHtt presponse对象,您可以调用getResponseBodyAsString()。

请参阅有关IgnitedHtt presponse更多的信息:
<一href=\"http://mttkay.github.com/ignition-docs/ignition-support/apidocs/com/github/ignition/support/http/IgnitedHtt$p$psponse.html\"相对=nofollow>链接

所有的一切,

 新IgnitedHttp(上下文)获得(URL)。发送()。getResponseBodyAsString()

时的回答你的第一个问题。你的第二个问题的回答是,IgnitedHttp也有上岗的方法,使等。

在这里是做了很多,你可能想要做什么太样本活动:https://github.com/mttkay/ignition/blob/master/ignition-support/ignition-support-samples/src/com/github/ignition/samples/support/IgnitedHttpSampleActivity.java

享受使用,我发现code最好的一块。

The documentation for [Ignition][1] is rather sparse. I'm looking at the documentation for the HTTP classes, such as link here, but I'm confused.

My current code looks something like this (sanitized version):

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);
}

How can I change this over to use the Ignition classes? I have two problems:

  1. I don't see how to initialize or use IgnitedHttpRequest. There are no constructors and no documentation that seems to explain the use of this class.
  2. Can IgnitedHttpRequest use GET requests, or only POST?
解决方案

Use the IgnitedHttp class : link

So,

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

Will return IgnitedHttpRequest object that you can call the send() method on.

See for more info on IgnitedHttpRequest : link

This send() will return an IgnitedHttpResponse object that you can call the getResponseBodyAsString().

See for more info on IgnitedHttpResponse :link

All in all,

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

Is the answer to your first question. Your 2nd question's answer is that IgnitedHttp also has methods for posts, puts, etc.

here is the sample activity that does a lot of what you may want to do too : https://github.com/mttkay/ignition/blob/master/ignition-support/ignition-support-samples/src/com/github/ignition/samples/support/IgnitedHttpSampleActivity.java

Enjoy using the best piece of code I've found.

这篇关于如何使用HTTP点火班,使Get请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:58