[英]php, curl, curl_exec()
我堅持嘗試處理表格 html 的隨機名稱和值,以通過 curl 發布數據。
這是我的代碼。
function grapvalue($html){
//parse content to grap name and value random
}
$opt = array(
CURLOPT_AUTOREFERER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookie.txt'
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => grapvalue($html)
)
$init = curl_init("site.com")
curl_setopt_array($init,$opt)
$html = curl_exec($init)
我必須執行 function curl_exec () 兩次,首先我必須執行 curl_exec function 以檢索 html 以獲取名稱和隨機值。 我該如何解決這個問題?
這是完整的解決方案:
//First, we make a request to grab the variables
function grapvalue(){
$opt = array(
CURLOPT_AUTOREFERER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookie.txt'
);
$init = curl_init("site.com");
curl_setopt_array($init,$opt);
$html = curl_exec($init);
//parse content to grap name and value random
}
//Than, just call grapvalue() without any parameters
$opt = array(
CURLOPT_AUTOREFERER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookie.txt'
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => grapvalue()
);
$init = curl_init("site.com");
curl_setopt_array($init,$opt);
$html = curl_exec($init);
提示:您可能更喜歡使用CURLOPT_COOKIE
而不是CURLOPT_COOKIEFILE
和CURLOPT_COOKIEJAR
。
為什么不創建function cURL()
,調用 function ,獲取$html
並使用 post 值再次調用?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.