When you access the data of a service software on the server through Http, the browser will pop up the following verification dialog box: because you want to use the PHPcurl method to obtain data, but do not know how to set the user name and password verification parameters: this does not work: {code ...} after using postman to simulate login, I found that...
When you access the data of a service software on the server over Http, the following verification dialog box is displayed in the browser:
I want to use the PHP curl method to obtain data, but I don't know how to set the user name and password verification parameters:
This discovery does not work:
curl_setopt($curl, CURLOPT_USERPWD, "name:pwd"); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
After using postman to simulate login, I found that there is one in the request header:
Then add a request header to the PHP curl method:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','Authorization:Basic TnhFY29AMjAxNjojQGlIeVg0eStHUFE='));
In this way, you can request data.
However, the problem is that the script needs to be put on the server for continuous operation. this write-dead verification will fail again after expiration, and there is no permission.
How can I set the php Curl username and password parameters to verify logon?
Reply content:
When you access the data of a service software on the server over Http, the following verification dialog box is displayed in the browser:
I want to use the PHP curl method to obtain data, but I don't know how to set the user name and password verification parameters:
This discovery does not work:
curl_setopt($curl, CURLOPT_USERPWD, "name:pwd"); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
After using postman to simulate login, I found that there is one in the request header:
Then add a request header to the PHP curl method:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','Authorization:Basic TnhFY29AMjAxNjojQGlIeVg0eStHUFE='));
In this way, you can request data.
However, the problem is that the script needs to be put on the server for continuous operation. this write-dead verification will fail again after expiration, and there is no permission.
How can I set the php Curl username and password parameters to verify logon?
This is php http verification. this is generally not the case. after all, HTTP Verification is too simple.
Http://php.net/manual/zh/feat...
$username='ABC';$password='XYZ';$URL='
';$ch = curl_init();curl_setopt($ch, CURLOPT_URL,$URL);curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 secondscurl_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);
Use CURL to simulate logon to get the Authorization Token
Use the Token obtained in step 1 for the next request.
The Token in step 1 can be properly cached, and the cache time depends on the server.
Digress: I personally think the server side is written in yii2.
Having done something similar before, I thought it was too troublesome for a long time and finally solved it with phantomjs. Php calls the node program.
Add this attribute
$user = 'hello';$pass = '$world';curl_setopt($ch, CURLOPT_USERPWD, "{$user}:{$pass}");