Accessing the HTTPS protocol from Java code

Source: Internet
Author: User

there is a web address on the Internet:https://wtsz.jyzq.cn/ywcl.jsp?type=l&yybdm=1100&market=z&username=11009341& pwd=870221&ip=3.3.3.3&servername=jyzq.cn, is the HTTPS protocol, how the Java program can call the address to get the correct return data.

The current address is accessible through a browser and needs to be accessed through a Java program in the background.

import java.io.ioexception;import java.io.inputstreamreader;import java.net.url;import  Javax.net.ssl.httpsurlconnection;public class test {public static void main ( String[] args)  throws ioexception {url requrl = new url ("https:// wtsz.jyzq.cn/ywcl.jsp?type=l&yybdm=1100&market=z&username=11009341&pwd=870221&ip=3.3.3.3 &servername=jyzq.cn "); //  Create the URL object httpsurlconnection httpsconn =  ( httpsurlconnection)  requrl.openconnection ();/* *  The following code implements sending data to a Web page, enabling interactive access to the Web page   Httpsconn.setdooutput (True); * outputstreamwriter out = new *  OutputStreamWriter (Huc.getoutputstream (),  "8859_1")  out.write (  "..."  * );  Out.flush ();  out.close (); *///  gets the input stream of the connection to read the response content Inputstreamreader insr = new  inputstreamreader (Httpsconn.getinputstream ());//  reads the response content of the server and displays INt respint = insr.read ();while  (respint != -1)  {system.out.print ((char)  respint); Respint = insr.read ();}}}

Output:

0# #P8ZU08YAE77TFB9T4HRC93ZGBOZNSHDY


Groovy version:

import javax.net.ssl.httpsurlconnection             url requrl = new url (                  "https://wtsz.jyzq.cn/ywcl.jsp?type=l&yybdm=1100&market=z& username=11009341&pwd=870221&ip=3.3.3.3&servername=jyzq.cn "); //  Create URL object          HttpsURLConnection httpsConn =  (httpsurlconnection)   requrl                . OpenConnection ();        /*          *  The following code implements sending data to a Web page, enabling interactive access to the page  httpsconn.setdooutput (true);          * OutputStreamWriter out = new          * outpUtstreamwriter (Huc.getoutputstream (),  "8859_1")  out.write (  "..."           * );  out.flush ();  out.close ();          */        //  gets the input stream of the connection to read the response content          inputstreamreader insr = new inputstreamreader (                  Httpsconn.getinputstream ());        //  reads the response of the server and displays the          int respint = insr.read ();         while  (respint != -1)  {             system.out.print ((char)  respint);             respint = insR.read ();         }//output: //0# #NQRCHIG6G7WJWMLKI5F1ETEGINNWT44X 

Note: I am using the JAVA 8 64-bit version. It is said that before in JAVA, access to the HTTPS protocol is quite cumbersome.

Java sends HTTPS requests, certificate configuration

http://blog.csdn.net/today1858/article/details/5859876

Java Secure Communications: HTTPS and SSL

Http://www.cnblogs.com/devinzhang/archive/2012/02/28/2371631.html



Accessing the HTTPS protocol from Java code

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.