HTTPS request with certificate sending message

Source: Internet
Author: User

public string SendXML (string Sendurl, String senddata) throws Exception {
File Trustedkeystorefile = new file (Ssltruststore);
BufferedReader reader = null;
Closeablehttpresponse resp = null;
String resultuestStr1 = null;
try {
Sslcontext Sslcontext = Sslcontexts.custom (). loadtrustmaterial (NULL, New Trustselfsignedstrategy ())
. loadkeymaterial (Trustedkeystorefile, Ssltruststorepassword.tochararray (),
Ssltruststorepassword.tochararray ())
. build ();

Sslconnectionsocketfactory sslsocketfactory = new Sslconnectionsocketfactory (Sslcontext,
New string[] {"TLSv1.2", "TLSv1.1", "TLSV1"}, NULL, New Noophostnameverifier ());

Closeablehttpclient client = Httpclients.custom (). Setsslsocketfactory (Sslsocketfactory). build ();
HttpPost post = new HttpPost (Sendurl);
httpentity entity = new Stringentity (SendData, "utf-8");
Post.setheader ("Content-type", "Text/xml");
Post.setentity (entity);
RESP = Client.execute (POST);
reader = new BufferedReader (New InputStreamReader (Resp.getentity (). GetContent ()));
StringBuilder datastring = new StringBuilder ();
String Inputline;
while ((Inputline = Reader.readline ()) = null) {
Datastring.append (Inputline). Append ("\ n");
}
RESULTUESTSTR1 = datastring.tostring (). Replace ("&lt;", "<");
} catch (Keymanagementexception E1) {
E1.printstacktrace ();
} catch (Unrecoverablekeyexception E1) {
E1.printstacktrace ();
} catch (NoSuchAlgorithmException E1) {
E1.printstacktrace ();
} catch (Keystoreexception E1) {
E1.printstacktrace ();
} catch (Certificateexception E1) {
E1.printstacktrace ();
} catch (IOException E1) {
E1.printstacktrace ();
}
return RESULTUESTSTR1;
}

HTTPS request with certificate sending message

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.