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

Custom HTTP methods #144

Open
arjunmenon opened this issue May 9, 2018 · 3 comments
Open

Custom HTTP methods #144

arjunmenon opened this issue May 9, 2018 · 3 comments

Comments

@arjunmenon
Copy link

Is there a way to call custom HTTP methods like SUBSCRIBE, NOTIFY with this?

@ghost
Copy link

ghost commented May 12, 2018

Hi @arjunmenon, Is this fixed?

@arjunmenon
Copy link
Author

I have moved on to okhttp

@Porsh33
Copy link

Porsh33 commented Jun 24, 2021

For future coders... #144 #91 #53

I need to use PATCH method. Thus, we got such a workaround. Can use any protocols

HttpRequest request;
if (method.equals("PATCH")) {
    request = new HttpRequest(url, "POST");
    HttpURLConnection conn = request.getConnection();
    Field statFinField = HttpURLConnection.class.getDeclaredField("method");
    statFinField.setAccessible(true);
    statFinField.set(conn, "PATCH");

    statFinField = HttpsURLConnectionImpl.class.getDeclaredField("delegate");
    statFinField.setAccessible(true);
    DelegateHttpsURLConnection z = (DelegateHttpsURLConnection)statFinField.get(conn);

    Field delegateField = HttpURLConnection.class.getDeclaredField("method");
    delegateField.setAccessible(true);
    delegateField.set(z, "PATCH");

    statFinField.set(conn, z);

    statFinField = HttpRequest.class.getDeclaredField("requestMethod");
    statFinField.setAccessible(true);
    statFinField.set(request, "PATCH");

}
else {
     request = new HttpRequest(url, method);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants