Created
March 17, 2020 22:48
-
-
Save naturalett/4650ec622efa9213dae61ec7e8f22cbc to your computer and use it in GitHub Desktop.
setRequestMethod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom HTTP request method | |
def setRequestMethod(HttpURLConnection c, String requestMethod) { | |
try { | |
final Object target; | |
if (c instanceof HttpsURLConnectionImpl) { | |
final Field delegate = HttpsURLConnectionImpl.class.getDeclaredField("delegate"); | |
delegate.setAccessible(true); | |
target = delegate.get(c); | |
} else { | |
target = c; | |
} | |
final Field f = HttpURLConnection.class.getDeclaredField("method"); | |
f.setAccessible(true); | |
f.set(target, requestMethod); | |
} catch (IllegalAccessException | NoSuchFieldException ex) { | |
throw new AssertionError(ex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment