此查詢重點在於使用Curl 登入Barnes & Noble 的行動網站,由於使用SSL 和cookie 而遇到困難。
要解決該問題,請考慮以下調整:
以下程式碼將這些調整合併到一個工作範例:
// Constants $EMAIL = '[email protected]'; $PASSWORD = 'yourpassword'; $COOKIE_FILE = "/tmp/cookies.txt"; $LOGIN_URL = "https://cart2.barnesandnoble.com/mobileacct/op.asp?stage=signIn"; $AGENT = "Nokia-Communicator-WWW-Browser/2.0 (Geos 3.0 Nokia-9000i)"; // Curl Initialization $ch = curl_init(); // Basic Headers $headers = ["Accept: */*", "Connection: Keep-Alive"]; // Curl Options curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, $AGENT); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIE_FILE); curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIE_FILE); // Step 1: Initialize with Login URL curl_setopt($ch, CURLOPT_URL, $LOGIN_URL); curl_exec($ch); // Step 2: Extract Form Fields $content = curl_getinfo($ch); $fields = getFormFields($content); // Populate Form Fields $fields['emailAddress'] = $EMAIL; $fields['acctPassword'] = $PASSWORD; // Extract X Value $loginUrl = "https://cart2.barnesandnoble.com/mobileacct/op.asp?x={$x}"; // Construct POST Fields $postFields = http_build_query($fields); // Update Login URL and POST Options curl_setopt($ch, CURLOPT_URL, $loginUrl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); // Perform Login and Retrieve Result $result = curl_exec($ch); print $result;
尋求進一步幫助在使用Curl 時,請考慮以下額外資源:
以上是如何使用 Curl、Cookie 和 SSL 登入 Barnes & Noble 的行動網站?的詳細內容。更多資訊請關注PHP中文網其他相關文章!