PHP file_get_contents() returns “failed to open stream: HTTP request failed!”

前端 未结 11 918
名媛妹妹
名媛妹妹 2020-11-22 13:03

I am having problems calling a url from PHP code. I need to call a service using a query string from my PHP code. If I type the url into a browser, it works ok, but if I use

11条回答
  •  半阙折子戏
    2020-11-22 13:56

    I got a similar problem.

    Due to timeout !

    Timeout can be indicated like this :

    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => "POST",
            'content' => http_build_query($data2),
            'timeout' => 30,
        ),
    );
    $context = stream_context_create($options); $retour =
    $retour = @file_get_contents("http://xxxxx.xxx/xxxx", false, $context);
    

提交回复
热议问题