dongshu9458 2019-02-05 07:27
浏览 240

PHP API错误 - 无法打开流:HTTP请求失败! HTTP / 1.1 401未经授权

I'm trying to query a website using the php query, but getting error:

$ php main.php

PHP Warning:  file_get_contents(https://api.transport.nsw.gov.au/v1/tp/stop_finder?
outputFormat=rapidJSON&type_sf=any&name_sf=Wynyard+Station&
coordOutputFormat=EPSG%3A4326&TfNSWSF=true): failed to open stream: HTTP request failed!
HTTP/1.1 401 Unauthorized
 in /home/cg/root/7504993/main.php on line 14.

Is there anything that I'm missing?

Tried - "Integrated Windows Authentication", under Tools > Security > Local Intranet zone > Sites > Advanced, the target web site is listed.

<?php
 // User's search query
 $apiEndpoint = 'https://api.transport.nsw.gov.au/v1/tp/';
 $apiCall = 'stop_finder';
 // Build the request parameters
 $params = array(
     'outputFormat' => 'rapidJSON',
     'type_sf' => 'any',
     'name_sf' =>'Wynyard Station',
     'coordOutputFormat' => 'EPSG:4326',
     'TfNSWSF' => 'true'
   );
  $url = $apiEndpoint . $apiCall . '?' . http_build_query($params);
  $response = file_get_contents($url);
  $json = json_decode($response, true);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 切换TabTip键盘的输入法
    • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥20 使用Photon PUN2解决游戏得分同步的问题
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序