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