如何通过用户名和密码访问安全区域


how to access a secure area passing username and password

我想访问此页面,该页面在输入正确的用户名和密码后返回一个xml文件http://webservices.ns.nl/ns-api-avt?station=ut我想将此xml传递给flash,但我不知道如何传递用户名和密码我很期待这样的事情username:password@webservices.ns.nl/ns-api-avt?station=ut或使用 php这里是该 API 的站点 URL,如果它有帮助 http://www.ns.nl/api/api

提前致谢

你可以在php中以多种方式做到这一点。

如果您碰巧在 Linux 环境中托管代码或具有本机 curl 支持,则可以

$call = "curl --basic --user {$username}:{$password} '"{$url}'"";
exec($call, $resp);
print_r($resp);

或者您可以使用 HTTP 库中的模块class.http.php

$http = new Http();
$http->useCurl(false);
$http->setMethod($method);
$http->setAuth($user, $pass);
$http->execute($url);
$resp = $http->error ? $http->error : $http->result;

PHP 示例与 curl on php.net: http://www.php.net/manual/en/function.curl-setopt.php#98164有趣的部分是:

curl_setopt($curl, CURLOPT_USERPWD, "username:password");