Bad Request with fsockopen?
Posted: Fri May 30, 2008 6:16 pm
Hi, I'm trying to use fopen to open and output a URL the code is below. This works fine, except when I try to use an https URL, it returns a "Bad Request" error. Can somebody tell me what I should do instead?
Code: Select all
$link = "http://www.google.com";
$http_response = "";
$url = parse_url($link);
$fp = fsockopen($url[host], 80, $err_num, $err_msg, 30) or die("Socket-open failed--error: ".$err_num." ".$err_msg);
fputs($fp, "GET /$url[path]?$url[query] HTTP/1.0\n");
fputs($fp, "Connection: close\n\n");
while(!feof($fp)) {
$http_response .= fgets($fp, 128);
}
fclose($fp);
echo $http_response;