S
S
stdio962017-03-21 23:41:26
Java
stdio96, 2017-03-21 23:41:26

How to make a PATCH request in Java?

Hello. I work with an API that, in order to update a record, waits for a PATCH request: it swears on POST. I found this on stackoverflow:

urlObject = new URL(url + urlParameters);
urlConnection = (HttpURLConnection) urlObject.openConnection();
urlConnection.setRequestProperty("accept-charset", "UTF-8");

urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("X-HTTP-Method-Override", "PATCH"); // взято со стековерфлоу

But the API server returns 405 method not allowed and a description of what the PATCH request is waiting for.
When I try to send a simple POST request, I get the same error.
Can someone come across such a situation (I'm sure that someone did and faced) and can advise on solutions? I will be grateful for any help.
PS: JSON is passed as parameters. API uses ODATA (specified just in case).
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2017-03-21
@aol-nnov

There is a Won't Fix bug in OpenJDK for this. However, with Apache Http-Components Client 4.2+ this is possible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question