linux curl get 数组,Curl POST作为GET执行

我正在尝试开发一种浏览器PHP.到目前为止,我class可以处理一个GET或一个POST请求Content Type:application/x-www-form-urlencoded.

现在我需要转向JSON一个.我把Content-Type标题设置为application/json.

事实是,使用这种类型我遇到了以下问题:设置POST请求将导致GET请求.这真的很奇怪.

这是我的代码:

private function request($url, $reset_cookies, $post_data = null, $custom_headers = null)

{

// Create options

$options = array(

CURLOPT_URL => $url,

CURLOPT_RETURNTRANSFER => 1,

CURLOPT_HEADER => 0,

CURLINFO_HEADER_OUT => 1,

CURLOPT_FAILONERROR => 1,

CURLOPT_USERAGENT => $this->user_agent,

CURLOPT_CONNECTTIMEOUT => 30,

CURLOPT_TIMEOUT => 30,

CURLOPT_FOLLOWLOCATION => 1,

CURLOPT_MAXREDIRS => 10,

CURLOPT_AUTOREFERER => 1,

CURLOPT_COOKIESESSION => $reset_cookies ? 1 : 0,

CURLOPT_COOKIEJAR => $this->cookies_file,

CURLOPT_COOKIEFILE => $this->cookies_file,

CURLOPT_HTTPHEADER => array('Accept-language: en'),

// SSL

/*

CURLOPT_SSL_CIPHER_LIST => 'TLSv1',

CURLOPT_SSL_VERIFYPEER => 1,

CURLOPT_CAINFO => dirname(__FILE__) . '/Entrust.netCertificationAuthority(2048).crt',

*/

);

// Add headers

if (isset($custom_headers)) $options[CURLOPT_HTTPHEADER] = array_merge($options[CURLOPT_HTTPHEADER], $custom_headers);

// Add POST data

if (isset($post_data))

{

$options[CURLOPT_POST] = 1;

$options[CURLOPT_POSTFIELDS] = is_string($post_data) ? $post_data : http_build_query($post_data);

}

// Attach options

curl_setopt_array($this->curl, $options);

// Execute the request and read the response

$content = curl_exec($this->curl);

print_r($options);

print_r(curl_getinfo($this->curl, CURLINFO_HEADER_OUT));

// Clean local variables

unset($url);

unset($reset_cookies);

unset($post_data);

unset($custom_headers);

unset($options);

// Handle any error

if (curl_errno($this->curl))

{

unset($content);

throw new Exception(curl_error($this->curl));

}

return $content;

}

为了说明我的问题,这是一个例子:

CUrl选项如下Array:

Array

(

[10002] => http://mywebsite.com/post/

[19913] => 1

[42] => 0

[2] => 1

[45] => 1

[10018] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2

[78] => 30

[13] => 30

[52] => 1

[68] => 10

[58] => 1

[96] => 0

[10082] => C:\wamp\www\v2\_libs/../_cookies/14d0fd2b-9f15-4ac5-8fae-4246cc6cef49.cookie

[10031] => C:\wamp\www\v2\_libs/../_cookies/14d0fd2b-9f15-4ac5-8fae-4246cc6cef49.cookie

[10023] => Array

(

[0] => Accept-language: en

[1] => RequestVerificationToken: 4PMxvJsQzFJ5oFt3JdUPe6Bp_geIj4obDJCYIRoU09PrrfcBSUgJT9iB3mXnGFc2KSlYrPcRHF7iHdQhGNu0GKLUzd5FywfaADbGS8wjhXraF36W0

[2] => Content-Type: application/json

)

[47] => 1

[10015] => {"usernameOrFeedId":"manitoba","feed_message_body":"Dummy message goes here"}

)

所以请求标题对我来说似乎很好,但我可能错了.

这是real由CUrl以下发送的标题:

GET /post/ HTTP/1.1

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2

Host: mywebsite.com

Accept: */*

Referer: http://mywebsite.com/post/

Cookie: ADRUM_BT=R%3a53%7cclientRequestGUID%3a9787a51b-b24d-4400-9d6a-efbd618c74c0%7cbtId%3a18790%7cbtERT%3a44; CSRFToken=o_eoIVji7pWclOsrLaJpZEbOFSBJBm851rHbH0Xqwdzw2tC5j07EAc23mlj-opWowgpj0RkHyiktl1cS6onBqI43afM1; WebSessionId=3aem0m2xpwmvesgphna5gaop; prod=rd101o00000000000000000000ffff0a5a2a74o80; AuthenticateCookie=AAAAAtsQgeb8+UXrJ+wa7CGVJKnqizEAo2bMuFvqvwYMAl1NRaa6z68LBRx9hiHzPBC8tYqiayHID6pHChGXB7VywemwTpGivcRQ3nRlUVuaYQKyxQt21p1mx7OMlLCsRA==; web_lang.prod=fr

Accept-language: en

RequestVerificationToken: 4PMxvJsQzFJ5oFt3JdUPe6Bp_geIj4obDJCYIRoU09PrrfcBSUgJT9iB3mXnGFc2KSlYrPcRHF7iHdQhGNu0GKLUzd5FywfaADbGS8wjhXraF34W0

Content-Type: application/json

正如您所看到的,这是一个GET请求,而后期数据看起来已经消失了.

我做错了吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值