我在php中写了一些帖子请求。 尝试使用firefox,请求可以正常工作,但不能使用curl。
public function action($key, $file){
$this->ch = curl_init();
$headers[] = "Accept-Encoding: gzip";
$headers[] = "Connection: Keep-Alive";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
$datas = "arg=test&action=upload";
curl_setopt($this->ch, CURLOPT_URL, "http://test.com");
curl_setopt($this->ch, CURLOPT_USERAGENT, $this->agent);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie_path);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie_path);
curl_setopt($this->ch, CURLOPT_POST, TRUE);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $datas);
curl_setopt($this->ch, CURLINFO_HEADER_OUT, 1);
$result = json_decode(curl_exec($this->ch));
echo curl_error($this->ch);
$info = curl_getinfo($this->ch);
var_dump($info);
curl_close($this->ch);
var_dump($result);
}
所以我没有错误,但out的标题如下: GET / HTTP / 1.1用户代理:Mozilla / 5.0(Windows; U; Windows NT 5.0; en-US; rv:1.4)Gecko / 20030624 Netscape / 7.1(ax),Mozilla主机:test.com接受: / 连接:Keep-Alive Content-Type:application / x-www-form-urlencoded
为什么标头使用GET而没有POST? 你能帮我吗?
亲切的问候
答案 0 :(得分:1)
我不确定我是否理解所有问题,但我可以向您展示cURL请求和响应可能是什么样子。 POST方法请求不关心用户代理。看看这对你有意义。我刚刚将信息发送给我的请求反射器。你可以在这里看到它: https://iconoun.com/demo/temp_f42.php
n = int(n)

响应看起来像这样......
n