Good day everyone, I am having trouble running a very simple test code that uses HttpClient, HttpRequest and BodyPublisher. Can anyone please help me verify if the response I get from running Serial.out.println(request.toString) is correct.
This is the output:
https://www.myserviceweb.com POST
I am expecting it to be like:
https://www.myserviceweb.com POST "some message body"
By the way below is my test code.
public class test {
public static void main(String[] args) throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://www.myserviceweb.com"))
.header("Content-Type", "text/plain; charset=UTF-8")
.POST(HttpRequest.BodyPublishers.ofString("some message body"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
Serial.out.println(request.toString());
Serial.out.println(response.toString());
}
}