简体   繁体   中英

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

According to the void setRequestMethod (String method) documentation here:

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

The allowed methods are limited to:

  • GET
  • POST
  • HEAD
  • 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:

E/MsgProcessingService: Failed while handling a message: java.net.ProtocolException: Unknown method 'NEXT'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE]

Is there a non-hacky way to bypass that method limitation?

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 . This method checks the String against a constant array.

As the spec says, these methods can be expanded, but it's very rare. The Heroku docs discuss this.

Related:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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