简体   繁体   English

如何在Android上将自己的方法与HttpURLConnection对象一起使用?

[英]How do I use my own method with an HttpURLConnection object on Android?

According to the void setRequestMethod (String method) documentation here: 根据void setRequestMethod (String method)文档在这里:

https://developer.android.com/reference/java/net/HttpURLConnection.html#setRequestMethod%28java.lang.String%29 https://developer.android.com/reference/java/net/HttpURLConnection.html#setRequestMethod%28java.lang.String%29

The allowed methods are limited to: 允许的方法仅限于:

  • GET 得到
  • POST POST
  • HEAD
  • OPTIONS OPTIONS
  • PUT
  • DELETE 删除
  • TRACE 跟踪

I have a server offering access to a list of messages and one of the options I have is to retrieve the next message: 我有一台服务器,可以访问消息列表,而我拥有的选项之一是检索一条消息:

NEXT /api/1/message

However, when I try to put NEXT as the method in the JavaScript HttpURLConnection I get an error: 但是,当我尝试将NEXT作为JavaScript HttpURLConnection中的方法时,出现错误:

E/MsgProcessingService: Failed while handling a message: java.net.ProtocolException: Unknown method 'NEXT'; E / MsgProcessingService:处理消息时失败:java.net.ProtocolException:未知方法'NEXT'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE] 必须是[OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE]中的一种

Is there a non-hacky way to bypass that method limitation? 是否有非hacky方式绕过该方法限制?

Obviously, I can create a new access point as follow on my server, but I was hoping I would not have to do that... 显然,我可以按照以下步骤在服务器上创建一个新的访问点,但是我希望不必这样做。

GET /api/1/message/next

No. 没有。

Those "methods" are defined in the HTTP spec . 这些“方法”在HTTP规范中定义。 This method checks the String against a constant array. 此方法对照常量数组检查String。

As the spec says, these methods can be expanded, but it's very rare. 正如规范所说,这些方法可以扩展,但是很少见。 The Heroku docs discuss this. Heroku文档对此进行了讨论。

Related: 有关:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM