微信搜索superit|邀请体验:大数据, 数据管理、OLAP分析与可视化平台 | 赞助作者:赞助作者

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

php aide_941 23℃

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

 

 

 


转换为 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;
}

转载请注明:SuperIT » linux bash curl 如何转换成php的curl请求

喜欢 (0)or分享 (0)