2 回答
TA贡献2065条经验 获得超14个赞
当访问一个 url 时
https://username:password@www.example.com/Protected/Export/MyFile.zip
您正在使用HTTP Basic Auth,它发送AuthorizationHTTP 标头。这与 无关ssh,因此您不能使用ssh2_connect().
要使用 php 访问它,您可以使用 curl:
$user = 'username';
$password = 'password';
$url = 'https://www.example.com/Protected/Export/MyFile.zip';
$curl = curl_init();
// Define which url you want to access
curl_setopt($curl, CURLOPT_URL, $url);
// Add authorization header
curl_setopt($curl, CURLOPT_USERPWD, $user . ':' . $password);
// Allow curl to negotiate auth method (may be required, depending on server)
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// Get response and possible errors
$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
// Save file
$file = fopen('/path/to/file.zip', "w+");
fputs($file, $reponse);
fclose($file);
- 2 回答
- 0 关注
- 198 浏览
添加回答
举报