1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| public static String httpRequestPostAR(String URLDestination,String XmlSoap,String RepKeyStore,String FicKeystore) //throws KeyStoreException, NoSuchAlgorithmException
{
Log.d("TIRAT",XmlSoap);
Log.d("TIRAT","******************************************************************************************");
String strResponse = null;
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
//HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(URLDestination);
StringEntity se = new StringEntity(XmlSoap);
se.setContentEncoding("application/soap+xml");
post.setEntity(se);
post.addHeader("Content-type", "application/soap+xml; charset=utf-8");
post.addHeader("SOAPAction", "urn:servicepecb2:4.0.1:calculer");
post.addHeader("Accept-Charset", "utf-8");
post.addHeader("Accept", "text/xml,application/text+xml,application/soap+xml");
//rajout code keystore
KeyStore trustStore= null;
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new File(".Keystore"));
try {
trustStore.load(instream, "XXXXXXX".toCharArray());
} finally {
instream.close();
}
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
//client.getConnectionManager().getSchemeRegistry().register(new Scheme("SSLSocketFactory", SSLSocketFactory.getSocketFactory(), 443));
//HttpResponse response = client.execute(post);
HttpResponse response = httpclient.execute(post);
HttpEntity entity = response.getEntity();
StringBuffer sb1 = new StringBuffer();
BufferedReader br1 = new BufferedReader(new InputStreamReader(entity.getContent()));
String in1 = "";
while ((in1 = br1.readLine()) != null)
{
sb1.append(in1 + "\n");
}
br1.close();
Log.d("TIRAT","sbuilder"+sb1.toString());
strResponse=sb1.toString();
}
catch (IOException e)
{
Log.d("TIRAT","Erreur"+e.getMessage().toString());
Log.d("TIRAT","Erreur"+e.getLocalizedMessage());
}
catch ( KeyStoreException e) {
Log.d("TIRAT","SSLKeyStoreException startup problem."+e.getLocalizedMessage());
}
catch ( NoSuchAlgorithmException e) {
Log.d("TIRAT","SSLNoSuchAlgorithmException startup problem."+e.getLocalizedMessage());
}
catch ( CertificateException e) {
Log.d("TIRAT","SSLCertificateException startup problem."+e.getLocalizedMessage());
}
catch ( KeyManagementException e) {
Log.d("TIRAT","SSLKeyManagementException startup problem."+e.getLocalizedMessage());
}
catch ( UnrecoverableKeyException e) {
Log.d("TIRAT","SSLUnrecoverableKeyException startup problem."+e.getLocalizedMessage());
}
return strResponse;
} |
Partager