今天就跟大家聊聊有關(guān)如何在php中使用file_get_contents對curl進行代替,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

file_get_contents代替使用curl其實不多見了,但有時你碰到服務(wù)器不支持curl時我們可以使用file_get_contents代替使用curl,下面看個例子。
當(dāng)用盡一切辦法發(fā)現(xiàn) 服務(wù)器真的無法使用curl時。或者curl不支持https時。curl https 出現(xiàn)502時。你又不想重裝網(wǎng)站環(huán)境的時候,你就改用file_get_contents 代替吧。
curl 經(jīng)常使用的 curl get curl post
curl get 替代 直接用file_get_contents($url) 就可以了
curl post 替代如下:
復(fù)制代碼 代碼如下:
function Post($url, $post = null) {
$content = http_build_query($post);
$content_length = strlen($content);
$options = array(
'http' => array(
'method' => 'POST',
'header' =>"Content-type: application/x-www-form-urlencoded",
'content' => $post
)
);
return file_get_contents($url, false, stream_context_create($options));
}
看完上述內(nèi)容,你們對如何在php中使用file_get_contents對curl進行代替有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
標(biāo)題名稱:如何在php中使用file_get_contents對curl進行代替-創(chuàng)新互聯(lián)
網(wǎng)址分享:http://chinadenli.net/article20/spgco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、品牌網(wǎng)站設(shè)計、靜態(tài)網(wǎng)站、用戶體驗、服務(wù)器托管、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容