Page 1 of 1

Java 11 HttpClient

PostPosted: Fri Oct 05, 2018 10:38 am
by pbankhead
Hi, I've been exploring the use of the JSON api with the new HttpClient in Java 11 and guided by this helpful documentation and the linked Python and Java code.

I haven't succeeded in logging in, and my best guess is that it's related to 'Referer'. When I try this:
Code: Select all
HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(url))
            .header("Content-Type", "application/json")
            .header("X-CSRFToken", this.token)
            .header("Referer", url)
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

it fails with the error
Code: Select all
restricted header name: "Referer"

while skipping that line fails with a 403 Forbidden response.

This earlier topic suggests 'Referer' is essential. Comparable code in Python works for me if Referer is specified, but fails if it isn't; GET requests are also working fine from my Java/Groovy code.

Is there anything I'm clearly doing wrong, some other workaround, or should I be giving up on HttpClient for now?

Thanks,

Pete

Re: Java 11 HttpClient

PostPosted: Mon Oct 08, 2018 8:45 pm
by jburel
Hi Pete
you are ahead of us!
We have not been evaluating Java 11 yet.
We will need a bit of time to investigate the issue.

Cheers
Jmarie

Re: Java 11 HttpClient

PostPosted: Wed Oct 24, 2018 11:03 am
by pbankhead
Thanks Jmarie! It looks like it should be possible to set the Referer for the Java 11 HttpClient as of 11.0.2 (according to this). In the meantime if I switch back to using HttpsURLConnection it works fine.