PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2025 → connexion a un web service securiser
connexion a un web service securiser
Iniciado por g.blanc, 10,may. 2019 16:01 - No hay respuesta
Publicado el 10,mayo 2019 - 16:01
Bonjour,
J'aimerai fair eun appel a un web service rest qui demande une authentification.
en java aucun souci. Je n'arrive malheureusement pas reproduire mon code java en windev ?

quelqu'un pour m'aider. Voici le code merci a tous



String https_url = "https://wsbexpress.dhl.com/rest/sndpt/ShipmentRequest";
URL url;
String Json_content = "{un_json}";

url = new URL(https_url);
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
String username="username";
String password="password";
byte[] message = (username+":"+password).getBytes("UTF-8");
String authEncoded = javax.xml.bind.DatatypeConverter.printBase64Binary(message);

con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Encoding", "gzip,deflate");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Basic "+authEncoded);

con.setDoOutput(true);

// faire la demande
OutputStream reqStream = con.getOutputStream();
reqStream.write(Json_content.getBytes());

// lire la réponse
StringBuilder responseSB = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ( (line = br.readLine()) != null)
responseSB.append(line);

// Close streams
br.close();
reqStream.close();