简体   繁体   中英

PHP file_get_contents 500 Internal Server error in php

My code is below:-

$context   = stream_context_create(array('http' => array(    
            'method' => "POST",           
        'header' => "Content-Type:text/xml\r\nUser-Agent:PHPRPC/1.1\r\n",        
        'content' => $request )));         
$file      = file_get_contents($this->server, false, $context);    

Warning: 
file_get_contents(http://abc.co.in/employers/index.php/JobPostingServices/getResponse):    
failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /var/www/project/client.php on line 40 

The problem is in your User-Agent header. This worked for me:

$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
$context = stream_context_create($opts);
$header = file_get_contents('https://www.example.com',false,$context);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM