I just started using the new HTTP client in Java and I'm unsure on how to pass parameters for a PUT request.
The specific request I'm dealing with requires an Authentication token and a parameter type.
- I've successfully dealt with the
Authenticationtoken using.headers() - I tried to do the same thing with the
typeparameter but I get an error message that states I haven't passed atypefield.
HttpClient client = HttpClient.newBuilder().build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("...")) # The API url
.headers("Authorization", token, "type", "type 1")
.POST(HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request,HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
typeparameter expected to be a header? isn't it a query parameter...URI.create("...?type=type1")?URI.create("...?param1 = ... ? param2 = ...)?type=type1¶m2=value2¶m3=value3¶m4=value4