HTTP requests with file_get_contents, getting the response code

前端 未结 5 2150
眼角桃花
眼角桃花 2020-11-27 15:39

I\'m trying to use file_get_contents together with stream_context_create to make POST requests. My code so far:

    $options = arra         


        
5条回答
  •  感动是毒
    2020-11-27 16:16

    I go to this page with kind of a different issue, so posting my answer. My problem was that I was just trying to suppress the warning notification and display a customized warning message for the user, so this simple and obvious fix helped me:

    // Suppress the warning messages
    error_reporting(0);
    
    $contents = file_get_contents($url);
    if ($contents === false) {
      print 'My warning message';
    }
    

    And if needed, turn back error reporting after that:

    // Enable warning messages again
    error_reporting(-1);
    

提交回复
热议问题