我试图将CURL数据发布到ASP页面。这是我尝试将数据发布到的网站:
https://www.evat.ir/vatlogin/frmLogi...px%3fp%3d1&p=1
它有两个字段,即用户名和密码,我试图通过使用CURL发布用户名和密码。 我怎么能这样做?
谢谢
答案 0 :(得分:0)
使用CURLOPT_USERPWD标头进行身份验证。
$username='your username';
$password='your password';
$URL='your asp url';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$result=curl_exec ($ch);
curl_close ($ch);
希望它会有所帮助
答案 1 :(得分:0)
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.yoursite.com/index.asp"); //url to post the data
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "variable1=username&variable2=password"); // use $_POST["username"] && $_POST["password"] while posting username and password
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$execute = curl_exec ($ch);
curl_close ($ch);
if ($execute == "OK") { echo " data successfully posted";}
else { echo "not posted";}
?>
希望这有帮助!