PHP:使用基本身份验证从不同的 Web 服务器下载文件?
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
包括将此请求标头放置在 HTTP 请求中:
现在如何将其放置在那里将取决于您用于建立此连接的方法。
Consists in placing this request header in the HTTP request:
Now how you're going to put it there will depend on the methods you are using to make this connection.
然后只需使用与操作文件相同的方法,例如。 fread、fgets、fclose 等
then just use the same methods as for manipulating files, eg. fread, fgets, fclose, etc.
我认为,如果他们告诉您“下载文件”,您可能会寻求实现基于 cURL 的解决方案:
PHP: cURL - 手册
您可以使用 Havenard 在他的帖子中列出的标头请求:
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:
他们可能意味着使用 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
我假设此人的意思是 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.