The URL interface at the beginning of HTTPS could not fetch data and error: PKIX Path building failed

Source: Internet
Author: User
Tags php language

About: PHP language written interface, through get or post to get the data inside. But it's a URL that starts with HTTPS.

Reason: HTTPS URL to the customer's certificate

Resolution: Skip the Certificate validation section

Package Com.scheduler;import;import;import;import;import;import;import;import;import  ;//This class masks the HTTPS connection requires authentication of the encryption certificate public class Gettextbyurl {public static void main (string[] args) {hostnameverifier HV = new Hostnameverifier () {public boolean verify (String Urlhostname, sslsession session) {Syst                Em.out.println ("Warning:url Host:" + urlhostname + "vs." + session.getpeerhost ());            return true;        }        };        StringBuffer msg = new StringBuffer ();            try {URL url = new URL ("https://www.ddsdd.php");            Trustallhttpscertificates ();            Httpsurlconnection.setdefaulthostnameverifier (HV);           URLConnection connection = Url.openconnection (); Connection.connect ();            BufferedReader in = new BufferedReader ((New InputStreamReader (Connection.getinputstream ()));            String Line;            while (line = In.readline ())! = null) {msg.append (line);            } String msgstring = Msg.tostring (); String fannlymsg = msgstring.substring (Msgstring.indexof ("!            ") + 1);        System.out.println (msgstring);        } catch (Malformedurlexception e) {e.printstacktrace ();        } catch (IOException e) {e.printstacktrace ();        } catch (Exception e) {e.printstacktrace (); }} private static void Trustallhttpscertificates () throws Exception {[] Trustallc        ERTs = new[1]; TM = new MiTM ();        TRUSTALLCERTS[0] = TM; sc = getinstance ("SSL"); Sc.init (NULL, TRUSTALLCERTs, NULL); (SC. getsocketfactory ()); } Static class MiTM implements, {public ja[] Getacceptedissuers () {return null; } public boolean isservertrusted ([] certs) {return TR        Ue } public boolean isclienttrusted ([] certs) {return TR        Ue                } public void checkservertrusted ([] certs, String authtype)        Throws {return;                } public void checkclienttrusted ([] certs, String authtype) Throws {REturn; }    }}


The URL interface at the beginning of HTTPS could not fetch data and error: PKIX Path building failed

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: 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.