如何使用HTTP点火班,使Get请求? [英] How to use Ignition HTTP classes to make Get request?

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

问题描述

文档[点火] [1] 是相当稀少。我在看的HTTP类的文档,如这里链接一>,但我很困惑。

我目前的code看起来像这样(消毒版):

 客户端= AndroidHttpClient.newInstance(MyConstants.USER_AGENT);
字符串URL = SaveConstants.MY_URL;
网址+ =? + MyConstants.MY_PARAMETER +=+的parameterValue;
HTTPGET请求=新HTTPGET(URL);
InputStream的contentStream = NULL;
尝试{
    HttpContext的HttpContext的=新BasicHttpContext();
    HTT presponse响应= client.execute(请求时,HttpContext的);
    contentStream = response.getEntity()的getContent()。
    字符串内容= Util.inputStreamToString(contentStream);
}

我怎样才能改变这种过度使用点火类?我有两个问题:


  1. 我不知道如何初始化或使用IgnitedHtt prequest。有没有构造函数和没有文件,这似乎解释了使用这个类。

  2. IgnitedHtt prequest可以使用GET请求,或只贴?


解决方案

使用的IgnitedHttp类:<一href=\"http://mttkay.github.com/ignition-docs/ignition-support/apidocs/com/github/ignition/support/http/IgnitedHttp.html\"相对=nofollow>链接

因此​​,

 新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也有上岗的方法,使等。

在这里是做了很多,你可能想要做什么太样本活动:<一href=\"https://github.com/mttkay/ignition/blob/master/ignition-support/ignition-support-samples/src/com/github/ignition/samples/support/IgnitedHttpSampleActivity.java\" rel=\"nofollow\">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请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆