消费定制请求方法采用Android [英] Consuming Custom Request Methods with Android

查看:115
本文介绍了消费定制请求方法采用Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发一个API,有需要提供自定义请求的方法是有意义的消费者的API(开发者)的。 标准设定的请求方法,按照 RFC-2616

In developing an API, there is a requirement to provide custom request methods that make sense to a consumer of the API (developer). The "standard" set of request methods, as per RFC-2616 are:

  • GET
  • PUT
  • POST
  • 删除
  • 跟踪
  • 连接

我想添加一个名为搜索。在API,使用PHP或Java,这很容易在PHP中实现。这种新的请求方法的消费被证明是一个Android <打击>挑战和iOS 开发。

I would like to add another, called SEARCH. On the API, using PHP or Java, this is easy to implement in PHP. The consumption of this new request method is proving to be a challenge for an android and iOS developer.

工作:

  • 在Javascript的
  • [通过JQuery或XDomainRequest作品]
  • 的Java
  • [通过HttpURLConnection的作品]
  • 在PHP [通过卷曲作品]:
  • Javascript [ works via JQuery or XDomainRequest ]
  • Java [ works via HttpUrlConnection ]
  • PHP [ works via cURL ]:

工作实例:

 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'SEARCH');

不工作:

  • <打击> <一个href="http://stackoverflow.com/questions/10076883/consuming-custom-request-methods-with-ios5">iOS
  • 在Android的[我的假设是,这应该可以正常工作,如果我有一个工作Java示例]

没有人有工作的例子或框架的任何引用,将支持自定义请求的方法,如搜索 FOOBAR

Does anyone have any references to working examples or frameworks that will support a custom request method, such as SEARCH, or FOOBAR?

亲切的问候

推荐答案

在Android的,如果你使用捆绑的Apache HttpClient库,你可以通过扩展的 的Htt prequestBase 。事实上,班所有标准的HTTP方法( HTTPGET HttpPost 等)在这个库中来自同一类扩展

In Android, if you use the bundled Apache Httpclient library, you can create a custom HTTP Method by extending HttpRequestBase. In fact, classes for all the standard HTTP methods (HttpGet, HttpPost etc) in this library extend from the same class.

如果你的搜索方法很相似的任何现有的方法,你可以直接继承了该类。例如,对于说明的目的,让我们假设它是非常接近的 GET 方法。然后,你可以创建一个类 HttpSearch 延伸 HTTPGET ,然后通过重写适当的方法定制的实现。

If your SEARCH method is very "similar" to any of the existing methods, you can directly extend that class. For instance, for the purpose of illustration, let's assume it is very close to the GET method. Then you could create a class HttpSearch which extends HttpGet and then customize the implementation by overriding appropriate methods.

一旦你有你的 HttpSearch 的实施做好​​准备,利用它类似于使用标准 HTTPGET 类:

Once you have your HttpSearch implementation ready, using it is similar to using a standard HttpGet class:

HttpClient client = new HttpClient;
//...
//...
HttpSearch search = new HttpSearch;
//...
client.execute(search);

这篇关于消费定制请求方法采用Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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