[英]http post in php without curl using username, password, param1, param2(string array)?
我有一個帶有主機鏈接和可以發布到的URL的表單。 該方法在網上可以正常運行,我想使用php自動輸入數據,如何做到不卷曲
它將像這樣傳遞(用戶名,密碼,示例,Example2)
示例2是帶有所需參數名稱的數據的字符串數組
如果根本沒有傳遞任何錯誤,則錯誤將顯示“登錄錯誤”
如果示例2為空,則會顯示“缺少根元素”。
另請參閱: 如何使用file_get_contents在PHP中發布數據?
基本上,您可以使用file_get_contents()和stream_context_create()發出POST請求。 在您的情況下:
$post = http_build_query(array(
"username" => "user",
"password" => "pw",
"example" => "...",
));
$context = stream_context_create(array("http"=>array(
"method" => "POST",
"header" => "Content-Type: application/x-www-form-urlencoded\r\n" .
"Content-Length: ". strlen($post) . "\r\n",
"content" => $post,
)));
$page = file_get_contents("http://example.com/login", false, $context);
只需打開與端口80的套接字連接,發送標頭即可(如果您想欺騙創建標頭,則可以使用livehttp標頭,只需在瀏覽器中發布並復制它即可觀看)。 然后在標題之后發送數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.