Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何以curl post的形式发出http请求?_Php_Http_Curl - Fatal编程技术网

Php 如何以curl post的形式发出http请求?

Php 如何以curl post的形式发出http请求?,php,http,curl,Php,Http,Curl,我已经做了一些HTTP篡改数据并试图制作我自己的curl帖子,但我恐怕无法理解这些东西是如何工作的,有人能解释一下我是如何把它放上去的吗?根据我在firefox上的可信篡改数据,在这个网站上提交数据有三个阶段,第一个阶段是 URL : http://www.thisiswebsite.xyz/Nginx/script/order_handler.php Method POST Type xmlhttprequest itemname : IFHPB-P14 orderstep :

我已经做了一些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
最后是提交post数据

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 POSThttp://www.thisiswebsite.xyz/Nginx/script/order_handler.php \
-主持人:www.thisiswebsite.xyz\
-H'连接:保持活力'\
-H'接受:text/html,*/*;q=0.01'\
-接受语言:en-US,en;q=0.5'\
-H'接受编码:gzip,deflate'\
-H’Referer:http://www.thisiswebsite.xyz/Nginx/index.php' \
-H'内容类型:application/x-www-form-urlencoded;字符集=UTF-8'\
-H'X-request-With:XMLHttpRequest'\
-H'内容长度:30'\
-H'Cookie:PHPSESSID=6gjfhn0475l29oanagdbugs022'\
-“Mozilla/5.0(Windows NT 10.0;Win64;x64;rv:65.0)Gecko/20100101 Firefox/65.0”\
--数据“itemname=IFHPB-P4&orderstep=3&username=cahya&hdsn=123&MAC=123”


问题:如何将这3个HTTP数据制作成一个简单的curl post?

将数据构建为一个关联数组,以制作键/值对

将标题构建为数组

初始化curl、设置所需选项、执行、捕获输出、关闭curl、打印结果

<?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");

?>


这与PHP有什么关系?可能想编辑您的标记…@Ivan因为它将使用php脚本,所以我可以将其作为php test.phpAh运行,所以您有一个工作命令行
curl
,您想转换为php+curl吗?@Ivan是的,正是我的人!如何在一个脚本中卷曲2个数据?我的意思是,这是一个不同的职位,所以我必须先发布这一个和另一个one@CahyaDarmaWijaya很简单,在关闭
curl
句柄之前,只需根据需要设置/更改选项(url和数据?),然后重新执行$数据=数组(),与您给我的
$data
数组相同,但是
$data1
$data
之后首先执行,请检查我的comment@CahyaDarmaWijaya是的,你能做到。玩它。