如何将此cURL命令转换为PHP代码?什么是“请求有效负载”?

时间:2018-05-19 14:08:47

标签: php curl networking cookies upload

所以,我正在上传JPG图像时正在检查网络。

enter image description here

作为curl命令的副本:

curl "https://admin-official.line.me/11702069/home/api/objects" -H "Origin: https://admin-official.line.me" -H "Accept-Encoding: gzip, deflate, br" -H "Accept-Language: en-US,en;q=0.9,id;q=0.8,de-DE;q=0.7,de;q=0.6" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBv1B9k1i89zlgjnA" -H "Accept: */*" -H "Referer: https://admin-official.line.me/11702069/home/send/" -H "Cookie: tzoffset=-420; _trmccid=6b030cba93d9db09; _ga=GA1.2.1058855825.1526457491; _gid=GA1.2.814129237.1526457491; ldsuid=CiDum1r75zWBJ3f7oLqRAg==; _trmcdisabled2=-1; _trmcuser=^{^\^"id^\^":^\^"^\^"^}; _ga=GA1.3.1058855825.1526457491; _gid=GA1.3.814129237.1526457491; plack_session_localaccount=XXX; minesota=XXX; minesota2=XXX-jdT5f_x10ov7Re12NliQw_zFyIe9osY4oOOc2Rxdy1gMyBhXbKdPmnpA2LHB9VhvlqlL_4hkeSNQK5SgU; plack_session=6cd2e4790ae9990303ea54f7f35b305fba801dc0; _trmcsession=^{^\^"id^\^":^\^"b8ba0724^\^",^\^"path^\^":^\^"/11702069/home/send/^\^",^\^"query^\^":^\^"^\^",^\^"time^\^":1526735963213,^\^"_dice^\^":0.09452730791211028^}; __try__=1526737592637; _trmcpage=/11702069/home/send/" -H "Connection: keep-alive" --data-binary ^"------WebKitFormBoundaryBv1B9k1i89zlgjnA^

Content-Disposition: form-data; name=^\^"file^\^"; filename=^\^"alpen.jpg^\^"^

Content-Type: image/jpeg^

^

^

------WebKitFormBoundaryBv1B9k1i89zlgjnA^

Content-Disposition: form-data; name=^\^"csrf_token^\^"^

^

vJiSf8AZPpAvqCp0JQtrNOMgrZRtrDpa1TEHbYLz^

------WebKitFormBoundaryBv1B9k1i89zlgjnA--^

^" --compressed

我以前从未见过这个,我不是卷毛的专家。但我正在使用curl to PHP coverter,但在这种情况下它不起作用。

编辑:这是我尝试过的。

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://admin-official.line.me/11702069/home/api/objects");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => "@".realpath('test.jpg'), "csrf_token" => $split2[0]));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

$headers = array();
$headers[] = "Origin: https://admin-official.line.me";
$headers[] = "Accept-Encoding: gzip, deflate, br";
$headers[] = "Accept-Language: en-US,en;q=0.9,id;q=0.8,de-DE;q=0.7,de;q=0.6";
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36";
$headers[] = "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBv1B9k1i89zlgjnA";
$headers[] = "Accept: */*";
$headers[] = "Referer: https://admin-official.line.me/11702069/home/send/";
$headers[] = 'Cookie: tzoffset=-420; _trmccid=6b030cba93d9db09; _ga=GA1.2.1058855825.1526457491; _gid=GA1.2.814129237.1526457491; ldsuid=CiDum1r75zWBJ3f7oLqRAg==; _trmcdisabled2=-1; _trmcuser={"id":""}; _ga=GA1.3.1058855825.1526457491; _gid=GA1.3.814129237.1526457491; plack_session_localaccount=XXX; minesota=XXX; minesota2=XXX; plack_session=XXX; _trmcsession={"id":"b8ba0724","path":"/11702069/home/send/","query":"","time":1526735963213,"_dice":0.09452730791211028}; __try__=1526737592637; _trmcpage=/11702069/home/send/';
$headers[] = "Connection: keep-alive";
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
echo $result;
?>

2 个答案:

答案 0 :(得分:2)

&#34;请求有效载荷&#34;是请求正文。 HTTP请求分为两部分,标题正文(Chrome会在此处调用请求负载的正文,不确定这是否是一个&#39>官方名称,或只是铬开发的心血来潮

无论如何,你正在使用{* 1}}方法,这种方法在PHP 5.5中被禁止,在PHP 5.6中默认禁用,并在PHP7中完全删除。

改为使用@,例如:

CURLFile

另外,请勿手动设置 Accept-Encoding 标头。您指定 gzip,deflate,br curl_setopt($ch, CURLOPT_POSTFIELDS, array( "file" => new CURLFile('test.jpg'), "csrf_token" => $split2[0] )); 不支持 br ,并且根据curl的编译方式,可能不会甚至支持gzip / deflate(虽然它通常会这样做),删除它。

另外,将libcurl设置为CURLOPT_ENCODINGemptystring将列出为支持而构建的所有编码(通常为 gzip deflate ,但不保证是)

另外,在使用curl@方法时,请不要手动设置 Content-Type 标题,因为如果curl的边界没有&与您在 Content-Type 标头中设置的内容相匹配,服务器无法正确读取请求。 CURLFile会为您设置此标题,如果您不覆盖它,那么就不要。

答案 1 :(得分:0)

使用Postman计算出来。

* What went wrong:
Execution failed for task ':app:transformDexWithDexForRelease'.
> com.android.build.api.transform.TransformException: 
com.android.ide.common.process.ProcessException: 
java.util.concurrent.ExecutionException: com.android.dex.DexException: 
Multiple dex files define Lcom/facebook/binaryresource/BinaryResource;