Mailing List webobjects-dev@wocommunity.org Message #447
From: Hugi Thordarson <hugi@karlmenn.is>
Subject: Re: [WO-DEV] Https request examples?
Date: Mon, 8 May 2023 17:16:27 +0000
To: WebObjects & WOnder Development <webobjects-dev@wocommunity.org>
Hi Markus,

is the server using a self-signed certificate? If not, i.e. it's just good ol' https with a cert issued by a trusted CA, you should be fine using the build in java http client with https, something likeā€¦

-----------------------

public static String post( final String url, final String requestBody ) throws IOException, InterruptedException {
// Create a client (the client can be reused so for performance sensitive code, I wouldn't do this within the method)
final HttpClient client = HttpClient
.newBuilder()
.build();

// Construct a request to submit
final HttpRequest request = HttpRequest
.newBuilder()
.uri( URI.create( url ) )
.POST( BodyPublishers.ofString( requestBody, StandardCharsets.UTF_8 ) )
.build();

// Submit the request
final HttpResponse<String> response = client.send( request, HttpResponse.BodyHandlers.ofString( StandardCharsets.UTF_8 ) );
return response.body();
}

-----------------------

- hugi


> On 8 May 2023, at 14:34, Markus Ruggiero (rucotec) <markus.ruggiero@rucotec.ch> wrote:
>
> I need to make a https POST request to a 3rd party web server sending xml along in the body of the request. The server is supposed to return a html page which I should then display inside an iFrame.
>
> Does any body have some example code how to do such an https request? Easy to create the xml but I am not quite sure about the SSL/TLS part.
>
> Thanks a lot
> ---markus---
>

Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster