php curl post 不能发json数据吗
答案:2 悬赏:0
解决时间 2021-03-14 06:06
- 提问者网友:枫涩帘淞幕雨
- 2021-03-14 00:12
php curl post 不能发json数据吗
最佳答案
- 二级知识专家网友:何以畏孤独
- 2021-03-14 00:24
可以啊,把你代码贴出来
添加header
application/json
添加header
application/json
全部回答
- 1楼网友:野性且迷人
- 2021-03-14 01:34
可用我的函数。 public function post($url, $post_data) { $this->_ch = curl_init(); curl_setopt($this->_ch, curlopt_useragent, 'mozilla/5.0 (windows nt 6.1; rv:22.0) gecko/20100101 firefox/22.0'); curl_setopt($this->_ch, curlopt_followlocation, true); curl_setopt($this->_ch, curlopt_maxredirs, 5); curl_setopt($this->_ch, curlopt_header, 0); curl_setopt($this->_ch, curlopt_returntransfer, true); curl_setopt($this->_ch, curlopt_ssl_verifypeer, false ); curl_setopt($this->_ch, curlopt_ssl_verifyhost, false ); curl_setopt($this->_ch, curlopt_encoding, "" ); curl_setopt($this->_ch, curlopt_post, true); curl_setopt($this->_ch, curlopt_postfields, $post_data); curl_setopt($this->_ch, curlopt_cookiefile, getcwd () . '/cookie.txt' ); curl_setopt($this->_ch, curlopt_cookiejar, getcwd () . '/cookie.txt' ); curl_setopt($this->_ch, curlopt_url, $url); $this->_body = curl_exec($this->_ch); $this->_info = curl_getinfo($this->_ch); $this->_error = curl_error($this->_ch); curl_close($this->_ch); }
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯