您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)php curl數(shù)據(jù)傳不過(guò)去該怎樣處理,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
php curl數(shù)據(jù)傳不過(guò)去的解決辦法:1、打開(kāi)相應(yīng)的PHP代碼文件;2、修改提交方式為“$post_data = "username=bob&key=12345";$response = http_req(...);”即可。
本文操作環(huán)境:Windows7系統(tǒng)、PHP7.1版,DELL G3電腦
php curl數(shù)據(jù)傳不過(guò)去怎么辦?
php curl post提交數(shù)據(jù)失敗解決方法
代碼如下:
function http_req($http_type, $method, $url, $data) { $ch = curl_init(); if (strstr($http_type, 'https')) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } if ($method == 'post') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } else { $url = $url . '?' . $data; } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100000);//超時(shí)時(shí)間 try { $ret = curl_exec($ch); } catch (Exception $e) { curl_close($ch); return json_encode(array('ret' => 0, 'msg' => 'failure')); } curl_close($ch); return $ret; } //第一種提交方式在遇到post_data 中包含@等一些符號(hào)時(shí)會(huì)出現(xiàn)提交失敗的情況 $url = "http://localhost/web_services.php"; $post_data = array ("username" => "bob","key" => "12345"); $response = http_req('http', 'post', $url, $post_data ); //第二種提交方式可以避免 $url = "http://localhost/web_services.php"; $post_data = "username=bob&key=12345"; $response = http_req('http', 'post', $url, $post_data );
關(guān)于php curl數(shù)據(jù)傳不過(guò)去該怎樣處理就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。