導航:首頁 > 編程語言 > phpcurldata

phpcurldata

發布時間:2022-06-30 03:01:08

A. php curl 無法將url中的內容獲取到變數之中

functioncurl_get_contents($url){
$curl=curl_init();
//設置你需要抓取的URL
curl_setopt($curl,CURLOPT_URL,$url);
//設置header
curl_setopt($curl,CURLOPT_HEADER,1);
//設置cURL參數,要求結果保存到字元串中還是輸出到屏幕上。
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
//運行cURL,請求網頁
$data=curl_exec($curl);
//關閉URL請求
curl_close($curl);
return$data
}

B. PHP的curl模塊和python的pycurl模塊的區別

C的curl:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://postit.example.com/moo.cgi");
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return ;
}

php的curl:
<?php
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www..com');
$data = curl_exec($c);
curl_close($c);
echo $c;
?>

python的pycurl:
import pycurl
def body(buffer):
print buffer
c = pycurl.Curl()
c.setopt(pycurl.URL, "http://www..com/")
c.setopt(pycurl.WRITEFUNCTION, body)
c.perform()

主要原理:

C:

使用到的數據結構:
typedef void CURL; /*當初始化什麼的時候只是一個void類型*/
struct SessionHandle {
struct Names dns;
struct Curl_multi *multi; /* 用於多線程處理*/
struct Curl_one_easy *multi_pos; /* if non-NULL, points to the its position
in multi controlling structure to assist
in removal. */
struct Curl_share *share; /* Share, handles global variable mutexing */
struct HandleData reqdata; /* Request-specific data */
struct UserDefined set; /* values set by the libcurl user ,用於setopt等*/
struct DynamicStatic change; /* possibly modified userdefined data */
struct CookieInfo *cookies; /* the cookies, read from files and servers */
struct Progress progress; /* for all the progress meter data */
struct UrlState state; /* struct for fields used for state info and
other dynamic purposes */
struct PureInfo info; /* stats, reports and info data */
#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
iconv_t outbound_cd; /* for translating to the network encoding */
iconv_t inbound_cd; /* for translating from the network encoding */
iconv_t utf8_cd; /* for translating to UTF8 */
#endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
unsigned int magic; /* set to a CURLEASY_MAGIC_NUMBER */
};
struct UserDefined {
FILE *err; /* the stderr user data goes here */
void *debugdata; /* the data that will be passed to fdebug */
char *errorbuffer; /* (Static) store failure messages in here */
long proxyport; /* If non-zero, use this port number by default. If the
proxy string features a ":[port]" that one will override
this. */
/**一下省略10000行- -**/
};

使用的方法1:

.初始化curl,得到sessionhandler結構體空間
CURL *curl_easy_init(void)
{
CURLcode res;
struct SessionHandle *data;
/* Make sure we inited the global SSL stuff */
if (!initialized) {
res = curl_global_init(CURL_GLOBAL_DEFAULT);
if(res) {
/* something in the global init failed, return nothing */
DEBUGF(fprintf(stderr, "Error: curl_global_init failedn"));
return NULL;
}
}
/* We use curl_open() with undefined URL so far */
res = Curl_open(&data);
if(res != CURLE_OK) {
DEBUGF(fprintf(stderr, "Error: Curl_open failedn"));
return NULL;
}
return data;
}

C. curl命令在PHP中怎麼用

這是我項目中一直在用的一個方法

<?php
functioncurl($url,$params=array(),$header=array(),$timeout=180){
if(empty($url))return$url;

$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);//請求url地址

curl_setopt($curl,CURLOPT_HTTPHEADER,$header);//構造IP

if(!empty($params)&&count($params)>0){
curl_setopt($curl,CURLOPT_POST,true);

//RequestPayload格式數據
if(isset($params['is_json'])&&$params['is_json']===true){
unset($params['is_json']);
$params=json_encode($params);
}else{
$params=http_build_query($params);
}
curl_setopt($curl,CURLOPT_POSTFIELDS,$params);
}

//curl_setopt($curl,CURLOPT_HEADER,true);//是否返回響應頭信息
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);//是否將結果返回
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,true);//是否重定向
//curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0(WindowsNT6.1;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/51.0.2704.106Safari/537.36');
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);//只信任CA頒布的證書
//curl_setopt($curl,CURLOPT_CAINFO,$cacert);//CA根證書(用來驗證的網站證書是否是CA頒布)
//curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,2);//檢查證書中是否設置域名,並且是否與提供的主機名匹配
//從證書中檢查SSL加密演算法是否存在
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($curl,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
//curl_setopt($curl,CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt($curl,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,$timeout);//用來告訴PHP腳本在成功連接伺服器前等待多久(連接成功之後就會開始緩沖輸出),這個參數是為了應對目標伺服器的過載,下線,或者崩潰等可能狀況;
curl_setopt($curl,CURLOPT_TIMEOUT,$timeout);//用來告訴成功PHP腳本,從伺服器接收緩沖完成前需要等待多長時間。如果目標是個巨大的文件,生成內容速度過慢或者鏈路速度過慢,這個參數就會很有用。
//自動設置Referer
curl_setopt($curl,CURLOPT_AUTOREFERER,1);
//curl_setopt($curl,CURLOPT_COOKIEJAR,"D:phpStudyWWWcjcooBE66.tmp");////寫入cookie信息
//setcookie('cookie_jar',$cookie_jar);//保存cookie路徑
$data=curl_exec($curl);//執行
curl_close($curl);
return$data;
}
?>

D. 使用php curl 模擬post請求,自動附加了data參數

$post_data_string=http_build_query($post_data,'&');

$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$get_session_url);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$xmloutput=curl_exec($ch);

一般這樣寫 你自己對比下

E. 請問php高手一個關於curl的問題

$szUrl = "url";
$UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $szUrl);
curl_setopt($curl, CURLOPT_HEADER, 0); //0表示不輸出Header,1表示輸出
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE);
$data = curl_exec($curl);
echo htmlx($data);

function htmlx($str){ $str = str_replace(">", str_replace(' ','',"& gt;"), $str);
$str = str_replace("<", str_replace(' ','',"& lt;"), $str);
$str = str_replace("\"", str_replace(' ','',"& quot;"), $str);
$str = str_replace(" ", str_replace(' ','',"& nbsp;"), $str);return $str;}
exit();

F. php curl 如何接收

<?php
/*這是個curlget方法實例,$url是需要獲取的地址*/
$url="http://www.hao123.com/";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$data=curl_exec($ch);//講上面url頁面的源代碼獲取並保存到$data這個變數中
curl_close($ch);
echo$data;
?>

G. php curl 取不到數據 幫我看下 是為什麼

有以下幾種可能:

1、伺服器端確實沒有數據返回;

2、curl寫錯了;

3、試試下面這個,我在用的

functioncurl($url,$post='POST',$data=array()){
$ch=curl_init();
$headers[]="Accept-Charset:utf-8";
curl_setopt($ch,CURLOPT_URL,$url);

curl_setopt($ch,CURLOPT_CUSTOMREQUEST,$post);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch,CURLOPT_SSLVERSION,1);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);

curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0(compatible;MSIE5.01;WindowsNT5.0)');
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_AUTOREFERER,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

$result=curl_exec($ch);
curl_close($ch);
returnjson_decode($result,1);
}

H. PHPcurl模擬登陸中的$data和$url應該如何找

chrome的話直接右鍵有復制curl內容

支予$data和$url兩個變數以一邊經驗來說 $url就是POST請求的url地址,$data就是POST的內容。

I. php curl如何直接轉發當前php接收的headersget請求如何直接轉發get參數post請求如何直接轉發post參數

本文實例講述了php使用CURL模擬GET與POST向微信介面提交及獲取數據的方法。分享給大家供大家參考,具體如下:
php CURL函數可以模仿用戶進行一些操作,如我們可以模仿用戶提交數據也可以模仿用戶進行網站訪問了,下面我們來介紹利用CURL模擬進行微信介面的GET與POST例子,例子非常的簡單就兩個:
Get提交獲取數據
/**
* @desc 獲取access_token
* @return String access_token
*/
function getAccessToken(){
$AppId = '1232assad13213123';
$AppSecret = '2312312321adss3123213';
$getUrl = 'htq.com/cgi-bin/token?grant_type=client_credential&appid='.$AppId.'&secret='.$AppSecret;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $getUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURL_SSLVERSION_SSL, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);
$response = json_decode($data);
return $response->access_token;
}

post提交獲取數據
/**
* @desc 實現天氣內容回復
*/
public function testWeixin(){
$access_token = $this->getAccessToken();
$customMessageSendUrl = 'ht.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
$description = '今天天氣的詳細信息(從第三方獲取)。';
$url = ttpr.com/';
$picurl = 'her.com/';
$postDataArr = array(
'touser'=>'OPENID',
'msgtype'=>'news',
'news'=>array(
'articles'=>array(
'title'=>'當天天氣',
'description'=>$description,
'url'=>$url,
'picurl'=>$picurl,
),
),
);
$postJosnData = json_encode($postDataArr);
$ch = curl_init($customMessageSendUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postJosnData);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);
var_mp($data);
}

例子相對來說比較簡單也沒有什麼好詳細分析的了,大家照抄就可以實現我們想要的功能了.

J. PHP_CURL求開啟辦法!!!

配置php支持curl
curl是一個利用URL語法在命令行方式下工作的文件傳輸工具。它支持很多協議:FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以及 LDAP。curl同樣支持HTTPS認證,HTTP POST方法, HTTP PUT方法, FTP上傳, kerberos認證, HTTP上傳, 代理伺服器, cookies, 用戶名/密碼認證, 下載文件斷點續傳, 上載文件斷點續傳, http代理伺服器管道( proxy tunneling), 甚至它還支持IPv6, socks5代理伺服器, 通過http代理伺服器上傳文件到FTP伺服器等等,功能十分強大。Windows操作系統下的網路螞蟻,網際快車(FlashGet)的功能它都可以做到。准確的說,curl支持文件的上傳和下載,所以是一個綜合傳輸工具,但是按照傳統,用戶習慣稱curl為下載工具。
配置方法:
1、拷貝PHP目錄中的libeay32.dll 和 ssleay32.dll 兩個文件到 system32 目錄。
2、修改php.ini:配置好 extension_dir ,去掉 extension = php_curl.dll 前面的分號。
---------------------------
php下擴展php_curl.dll的安裝
---------------------------
已經內置有php_curl.dll,在ext目錄下,此DLL用於支持SSL和zlib.
在php.ini中找到有extension=php_curl.dll, 去掉前面的注釋.
設置extension_dir=c:phpext, 刷新PHP頁面時報錯, 說找不到模塊php_curl.dll.
拷貝php_curl.dll 到windowssystem32,還是同樣的錯.
在網上找了一下,需要將:
libeay32.dll, ssleay32.dll, php5ts.dll, php_curl.dll
都拷貝到system32目錄下,重啟IIS即可.

閱讀全文

與phpcurldata相關的資料

熱點內容
javajunit4for 瀏覽:843
華為伺服器如何進陣列卡配置 瀏覽:433
apache伺服器ip地址訪問 瀏覽:718
如何買到安卓手機預裝軟體 瀏覽:537
冤罪百度雲不要壓縮 瀏覽:85
蘇州雲存儲伺服器 瀏覽:173
解壓收納原聲 瀏覽:384
java注冊驗證 瀏覽:374
火花app怎麼上推薦 瀏覽:980
什麼app能游戲投屏到電視上 瀏覽:455
伺服器託管到雲端是什麼意思 瀏覽:835
app保存草稿怎麼用 瀏覽:808
安卓如何進入proumb 瀏覽:144
主機虛擬雲伺服器 瀏覽:619
刪除分區加密的空間會不會恢復 瀏覽:706
京東app客戶上門怎麼看搜索量 瀏覽:741
怎麼在農行app購買黃金 瀏覽:46
c型開發板和單片機 瀏覽:146
虛擬機建立用戶的模板文件夾 瀏覽:904
無錫代碼編程培訓班 瀏覽:632