且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将Linux Curl转换为PHP

更新时间:2023-02-16 19:46:54

您问以下linux终端 curl 命令如何关联到PHP curl的选项:

You asked how the following linux terminal curl command relates to the options of PHP curl:

curl -k -i -H内容类型:application / x-www-form-urlencoded -c cookies.txt -X POST https://192.168.100.100:444/appserver/j_spring_security_chec‌k -d j_username = admin& j_password = demoserver

以下是上述选项/标志的列表:

Here is a list of the above options/flags:


  • -k = CURLOPT_SSL_VERIFYPEER:false

  • -i = CURLOPT_HEADER:true

  • -H = CURLOPT_HTTPHEADER

  • -c = CURLOPT_COOKIEJAR + CURLOPT_COOKIEFILE

  • -X POST = CURLOPT_POST:是

  • -d = CURLOPT_POSTFIELDS

  • -k = CURLOPT_SSL_VERIFYPEER: false
  • -i = CURLOPT_HEADER: true
  • -H = CURLOPT_HTTPHEADER
  • -c = CURLOPT_COOKIEJAR + CURLOPT_COOKIEFILE
  • -X POST = CURLOPT_POST: true
  • -d = CURLOPT_POSTFIELDS

这将导致以下结果:

<?php
    $ch = curl_init();
    $url  = "https://192.168.100.100:444/appserver/j_spring_security_chec‌​k";
    $postData = 'j_username=admin&j_password=demoserver';
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_POST, 1); // -X
    curl_setopt($ch, CURLOPT_POSTFIELDS,$postData); // -d
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'application/x-www-form-urlencoded'
    )); // -H
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); // -c
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); // -c
    curl_setopt($ch, CURLOPT_HEADER, true); // -i
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // -k
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // see comment
    echo curl_exec ($ch);
    curl_close ($ch);

希望对您有所帮助。