PHP fatal error: Uncaught exception 'Exception' with message

前端 未结 5 1845
清酒与你
清酒与你 2021-01-19 08:13

I have a PHP script that connects to an api and posts information to their systems, but when its trying to connect it throws a fatal error:

Fatal error: Unca         


        
相关标签:
5条回答
  • 2021-01-19 08:25

    or You can change the headers:

    $optional_headers = 'Content-Type: application/json')
    
    0 讨论(0)
  • 2021-01-19 08:27

    apitestserver.co.uk doesn't respond to ping and the url is inaccessable. The API-server doesn't seem to be up.

    0 讨论(0)
  • 2021-01-19 08:34

    First error message suggests problems with apitestserver - it returns error code 500, which states for "Internal server error".

    Second one informs that PHP can't resolve host name into IP address - I'd look into DNS configuration and/or hosts file.


    Apparently 'fopen' function does not return proper stream. There can be many possibilities when that happens, but according to PHP manual, fopen function on fail should present E_WARNING message with proper commentary. It is possible that you have errors of that class silenced - call error_reporting(E_ALL) at the beginning of your script and look for some relevant error messages.

    0 讨论(0)
  • 2021-01-19 08:35

    I just tested the URL in my browser and got a connection error.

    Maybe the problem is with their server (or you have the wrong URL)?

    Edit:

    Looks like ther server is throwing a 500 error - maybe because the data you're posting is invalid.

    You could use a packet sniffer and check the exact data you're sending to the server (or use cURL as suggested by @acrosman)

    0 讨论(0)
  • 2021-01-19 08:40

    I would suggest using curl instead of fopen(). curl is both more flexible, and more secure. Many servers disable allow_url_fopen, curl also fails more gracefully when there are problems on the remote server.

    0 讨论(0)
提交回复
热议问题