PHP:使用基本身份验证从不同的 Web 服务器下载文件?

发布于 2024-08-03 02:08:42 字数 135 浏览 8 评论 0原文

我使用 PHP 一段时间了,但还不是太高级。我对服务器到服务器的事情没有太多经验。我需要研究与供应商建立数据馈送。与我交谈的联系人说我将通过基本身份验证使用用户名和密码从他们的服务器下载文件。有人可以给我详细说明如何做到这一点吗?

谢谢!!

I have been using PHP for a while but I am not too too advanced. I do not have much experience with server-to-server stuff. I need to research setting up a data-feed with a vendor. The contact person that I talked to said I would be downloading a file from their server using a username and password via basic authentication. Can someone please give me a break down on how to do that?

Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

原来分手还会想你 2024-08-10 02:08:42

包括将此请求标头放置在 HTTP 请求中:


$login = "havenard";
$pass  = "my l33t p4ssw0rd";

$header = "Authorization: Basic " . base64_encode("{$login}:{$pass}");

现在如何将其放置在那里将取决于您用于建立此连接的方法。

Consists in placing this request header in the HTTP request:


$login = "havenard";
$pass  = "my l33t p4ssw0rd";

$header = "Authorization: Basic " . base64_encode("{$login}:{$pass}");

Now how you're going to put it there will depend on the methods you are using to make this connection.

身边 2024-08-10 02:08:42
$f = fopen("http://$username:[email protected]"); 

然后只需使用与操作文件相同的方法,例如。 fread、fgets、fclose 等

$f = fopen("http://$username:[email protected]"); 

then just use the same methods as for manipulating files, eg. fread, fgets, fclose, etc.

习惯成性 2024-08-10 02:08:42

我认为,如果他们告诉您“下载文件”,您可能会寻求实现基于 cURL 的解决方案:
PHP: cURL - 手册

您可以使用 Havenard 在他的帖子中列出的标头请求:

$login = "havenard";
$pass  = "my l33t p4ssw0rd";
$auth = "Authorization: Basic " . base64_encode("{$login}:{$pass}");

I think that if they told you to "download a file", you might be looking to implement a cURL based solution:
PHP: cURL - Manual

And you can use the header request that Havenard listed in his post:

$login = "havenard";
$pass  = "my l33t p4ssw0rd";
$auth = "Authorization: Basic " . base64_encode("{$login}:{$pass}");
对不⑦ 2024-08-10 02:08:42

他们可能意味着使用 SOAP API,这种格式(通常)使用用户名/密码 + 函数调用来从服务获取/发布数据。搜索 php SOAP 或 nusoap 等。这应该足以让您开始使用。

然而,我会得到一个可靠的服务“名称”来使用。我在这里假设您使用的是 SOAP,因为这是我个人使用中最熟悉的。

编辑:
除非“基本身份验证”,否则它们的意思是:
http://us.php.net/manual/en/features。 http-auth.php

They probably mean using a SOAP API, this format uses (usually) a username/password + function call to get / post data from the service. Do a search on php SOAP, or nusoap, etc. That should give you enough to get started.

I would however get a solid 'name' of the service to use. I am assuming here for you that its SOAP as that is what I am most familiar with from personal usage.

Edit:
Unless by 'basic authentication' they mean:
http://us.php.net/manual/en/features.http-auth.php

掌心的温暖 2024-08-10 02:08:42

我假设此人的意思是 HTTPAuth 之类的内容,即在浏览器中访问某个页面时会弹出用户名/密码框,并且您需要在加载内容之前提供凭据。

为此,您可以使用 CURL。 PHP 有一组很好的curl 函数来处理这个问题。您需要使用 CURLOPT_NETRC 选项对其进行配置。

I assume that the person means something like HTTPAuth, which is when a username/password box pops up when going to a page in your browser, and you're required to give credentials before the content is loaded.

For this, you can use CURL. PHP has a nice set of curl functions for handling this. You'll need to configure it with the CURLOPT_NETRC option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文