Alexis Wilke
Alexis Wilke

Reputation: 20720

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:

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

Upvotes: 2

Views: 453

Answers (1)

jordanpg
jordanpg

Reputation: 6516

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:

Upvotes: 5

Related Questions