【发布时间】:2017-07-23 16:58:53
【问题描述】:
我在 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);
}
所以我没有错误,但输出的标题如下: 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 Host: test.com Accept: / 连接:Keep-Alive 内容类型:application/x-www-form-urlencoded
为什么标头使用 GET 而没有 POST ? 你能帮帮我吗?
亲切的问候
【问题讨论】: