cURL Login to HTTPS site

后端 未结 2 1820
悲&欢浪女
悲&欢浪女 2021-01-13 17:46

I have been trying to post login credentials to an https site using cURL and PHP with no luck. Everything works fine for unsecured sites but I can\'t get it with https. I kn

相关标签:
2条回答
  • 2021-01-13 18:22
    1. Export the certificate.
    2. Upload it to where your script can see it.
    3. Then add:

      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/path/to/certificateCA.crt");
      
    0 讨论(0)
  • 2021-01-13 18:40

    I used this once to connect to a bank account, hope this helps:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, HSBC_LINK1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    
    $post_data = array('post1' => 'value');
    
    $fields_string = '';
    foreach($post_data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
    $fields_string = rtrim($fields_string,'&');
    curl_setopt($ch, CURLOPT_POST, count($post_data)); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    $data1 = curl_exec($ch);
    
    0 讨论(0)
提交回复
热议问题