天天看點

PHP:6種GET和POST請求發送方法

無論是暢言還是多說,我都需要從遠端抓取文章的評論數,然後存入本地資料庫。對于多說,請求的格式如下:

對于遠端請求,有很多種方法。今天,LZ就搜羅了六種,供大家參考。

1、用file_get_contents 以get方式擷取内容:

   2、用fopen打開url,用get方式擷取

3、用file_get_contents 以post方式擷取内容:

    4、用fsockopen函數打開url,以get方式擷取完整的資料,包括header和body,fsockopen需要 PHP.ini 中 allow_url_fopen 選項開啟

     5、用fsockopen函數打開url,以POST方式擷取完整的資料,包括header和body

    6、使用curl庫,使用curl庫之前,可能需要檢視一下php.ini是否已經打開了curl擴充