J'ai utilisé cette classe java, pour me communiquer une valeur de ce lien https://httpbin.org/get . Mais il me donne la valeur 2 , pour dire il y a une IOException
package com.cni.appelws;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import org.json.JSONObject;
public class NetClientGet {
public static String appelws(){
try {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("172.16.128.1",8080));
URL url = new URL("https://httpbin.org/get");
HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line+"\n");
}
String ch = sb+"";
ch.replace("\"","\\\"");
JSONObject jsonData = new JSONObject(ch);
String qt = (String) jsonData.get("origin");
System.out.println(jsonData.get("origin"));
return qt;
//execution.setVariable("cgwf_solde",)
} catch (MalformedURLException e) {
e.printStackTrace();
return "1";
} catch (IOException e) {
e.printStackTrace();
return "2";
}catch (Exception e) {
return "3";
}
}
}
Ou est le pbm.