PHP Get XML from Remote URL with HTTP Authentication

后端 未结 5 1882
太阳男子
太阳男子 2021-01-14 02:21

I have a URL which gives an xml output. It requires a username and password which I can access through a browser using the format:

http://username:pa

5条回答
  •  [愿得一人]
    2021-01-14 03:19

    The format -- http://username:password@url.com -- is a convention the browser understands; but if you're making an HTTP request programmatically, you'll need to set the HTTP Headers for basic authentication. I don't think *simplexml_load_file* supports HTTP headers, but you could try using for example:

    fopen("http://$username:$password@url.com");
    

提交回复
热议问题