[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP method PATCH not supported #1316

Open
AngelLuisSanchez opened this issue Mar 12, 2021 · 2 comments
Open

HTTP method PATCH not supported #1316

AngelLuisSanchez opened this issue Mar 12, 2021 · 2 comments
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@AngelLuisSanchez
Copy link
AngelLuisSanchez commented Mar 12, 2021

Environment details

  • OS:Linux
  • Java version:1.8
  • google-http-java-client version: 1.38.1

Steps to reproduce

Hello everyone,

I am trying to make an http patch call with the google-http-client-1.38.1 library, but it is returning an error. I have no problem making HTTP GET, POST, or PUT calls.

I have debugged the library files and I have seen that the error occurs in the httpRequest class when it is going to build the request
LowLevelHttpRequest lowLevelHttpRequest = transport.buildRequest (requestMethod, urlString)
I build the request with the following format
val req = httpRequestFactory .buildRequest( "PATCH", GenericUrl(URL), HTTP_CONTENT) .setThrowExceptionOnExecuteError(false) .setLoggingEnabled(true) .setHeaders(HTTP_HEADERES)

Stacktrace

java.lang.IllegalArgumentException: HTTP method PATCH not supported

External references such as API reference guides used

I am using the google-http-client-1.38.1 through google-auth-library-oauth2-http 0.24.0

Thanks!

@Neenu1995 Neenu1995 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 12, 2021
@elharo elharo added feat and removed priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Apr 29, 2021
@Neenu1995 Neenu1995 added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed feat labels Apr 29, 2021
@spmeesseman
Copy link

u can set the header X-HTTP-Method-Override to PATCH, and send a POST as a workaround in most cases i would think

@njkevlani
Copy link

Not all servers will understand X-HTTP-Method-Override. This is what we did:

  1. Get access token from google credentials.
  2. Use this access token with webclient, which will allow you to make any sort of requests.
GoogleCredentials googleCredentials = GoogleCredentials.getApplicationDefault();

googleCredentials.refresh();

HttpHeaders headers = new HttpHeaders();

headers.setBearerAuth(googleCredentials.getAccessToken().getTokenValue());

WebClient.builder()
        .defaultHeaders(httpHeaders -> httpHeaders.addAll(headers));

WebClient webClient = webClientBuilder.build();
webClient.patch()
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

5 participants