linux bash curl 如何转换成php的curl请求

curl 'http://af.epicc.com.cn/api/misc/creditEntry/creditInfoSubmit' 
    -H 'Cookie:test' 
    -H 'Origin: http://af.epicc.com.cn' 
    -H 'Accept-Encoding: gzip, deflate' 
    -H 'X-Requested-With: XMLHttpRequest' 
    -H 'Accept-Language: zh-CN,zh;q=0.9' 
    -H 'Authorization: Arch6WithCloud null' 
    -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundary0vi094pNr9jxqbUH' 
    -H 'Accept: application/json, text/javascript, */*; q=0.01' 
    -H 'Referer: http://af.epicc.com.cn/' 
    -H 'jwtToken: test2' 
    -H 'Connection: keep-alive' 
    -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36' 
    --data-binary $'------WebKitFormBoundary0vi094pNr9jxqbUH\r\nContent-Disposition: form-data; name="saveFlag"\r\n\r\nsave\r\n------WebKitFormBoundary0vi094pNr9jxqbUH--\r\n' 
    --compressed
阅读 821
评论
    2 个回答

    转换为 PHP 对应下面的代码

    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "http://af.epicc.com.cn/api/misc/creditEntry/creditInfoSubmit",
      CURLOPT_RETURNTRANSFER => true,
      // 留空对应 --compressed
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "------WebKitFormBoundary0vi094pNr9jxqbUH\r\nContent-Disposition: form-data; name=\"saveFlag\"\r\n\r\nsave\r\n------WebKitFormBoundary0vi094pNr9jxqbUH--",
      CURLOPT_HTTPHEADER => array(
        "Cookie: test",
        "Origin: http://af.epicc.com.cn",
        "Accept-Encoding: gzip, deflate",
        "X-Requested-With: XMLHttpRequest",
        "Accept-Language: zh-CN,zh;q=0.9",
        "Authorization: Arch6WithCloud null",
        "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary0vi094pNr9jxqbUH",
        "Accept: application/json, text/javascript, /; q=0.01",
        "Referer: http://af.epicc.com.cn/",
        "jwtToken: test2",
        "Connection: keep-alive",
        "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
      ),
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }

      图片描述图片中红色区域的$符号是干什么的? 我感觉是这个$的作用没我再代码中没体现

        撰写回答

        登录后参与交流、获取后续更新提醒

        相似问题
        推荐文章