我已经完成了一些HTTP篡改数据并尝试创建自己的curl帖子,但是恐怕我无法理解这些功能的工作原理,有人可以解释一下我该如何使用它吗?根据我在firefox上可信赖的篡改数据,在此网站上提交数据分为三个阶段,第一阶段是
URL : http://www.thisiswebsite.xyz/Nginx/script/order_handler.php
Method POST
Type xmlhttprequest
itemname : IFHPB-P14
orderstep : 1
然后是我认为的HTTP标头
URL : http://www.thisiswebsite.xyz/Nginx/script/order_handler.php
Method POST
Type xmlhttprequest
Host : www.thisiswebsite
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0
Accept : text/html, */*; q=0.01
Accept-Language : en-US,en;q=0.5
Accept - Encoding : gzip, deflate
Referer : http://www.thisiswebsite/Nginx/index.php
Content-Type : application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With : XMLHttpRequest
Content-Length : 30
Connection : keep-alive
Cookie : PHPSESSID=6gjfhn0475l26oanag1bugs025
最后是提交帖子数据
URL : http://www.thisiswebsite.xyz/Nginx/script/order_handler.php
Method POST
Type xmlhttprequest
itemname : IFHPB-P14
orderstep : 3
username : testing
hdsn : datatest
MAC : datatestmac
我尝试卷曲
curl -X POST http://www.thisiswebsite.xyz/Nginx/script/order_handler.php \
-H 'Host: www.thisiswebsite.xyz' \
-H 'Connection: keep-alive' \
-H 'Accept: text/html, */*; q=0.01' \
-H 'Accept-Language: en-US,en;q=0.5' \
-H 'Accept - Encoding: gzip, deflate' \
-H 'Referer: http://www.thisiswebsite.xyz/Nginx/index.php' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'Content-Length: 30' \
-H 'Cookie: PHPSESSID=6gjfhn0475l29oanagdbugs022' \
-A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0' \
--data "itemname=IFHPB-P4&orderstep=3&username=cahya&hdsn=123&MAC=123"
问题:如何将这3个HTTP数据制作为简单的curl帖子?
答案 0 :(得分:1)
将数据构建为关联数组以创建键/值对。
将标头构建为数组。
初始化卷曲,设置所需的选项,执行,捕获输出,关闭卷曲,打印结果。
<?php
// build your data as an associative array for the keys
// and yes, you can use multi-dimensional arrays, etc
$data=array();
$data['item']="abc123";
$data['orderstep']=3;
$data['username']="joe.user";
$data['hsdn']=545;
$data['MAC']="bigmac";
// you can set options for various headers as needed, just
// do all of them as an array()
$headers=array();
$headers[]="Accept: text/html,*/*";
$headers[]="Referer: http://some.example.com";
$headers[]="Content-Type: application/x-www-form-urlencoded;charset=UTF-8";
// and so on...
// set the URL for your POST to go to
$url="http://api.example.com/end/point";
// now initialize curl
$ch=curl_init();
// set the options for your headers,
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
// and http method
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
// do you want to capture any returned output from server?
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
// what URL to call
curl_setopt($ch,CURLOPT_URL,$url);
// what data to send
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($data));
// make it so!
$curl_result=curl_exec($ch);
// done with curl
curl_close($ch);
// show results
print_r($curl_result."\n");
?>