An HTTP request.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

An HTTP request.

Post by JellyFish »

Code: Select all

<?php
	function HttpRequest($address, $data)
	{
		$url = parse_url($address);
		
		while (list($key, $value) = each($data))
		{
			$dataToPost .= "$key=$value&";
		}
		$dataToPost = rtrim($dataToPost, "&");
		
		$request = 	"POST ".$url['path']." HTTP/1.0\r\n"
		. "Host: ".$url['host']."\r\n"
		. "Content-Type: application/x-www-form-urlencoded;\r\n"
		. "Content-Length: ".strlen($dataToPost)."\r\n"
		. "\r\n"
		. $dataToPost;
		
		$socket = @fsockopen($url['host'], 80, $errno, $errstr) or die("Error: unable to open a socket connection with ".$url['host']."\n $errno: $errstr");
		fwrite($socket, $request);
		
		// Response
		$response = '';
		while (!feof($socket)) {
		    $response .= fpassthru($socket);
		}
		fclose($socket);
		
		return $response;
	}
?>

Code: Select all

HttpRequest("https://www.linkpointcentral.com/lpc/servlet/lppay", $anArray);
My question is: Would the above call to the function HttpRequest post $anArray to "https://www.linkpointcentral.com/lpc/servlet/lppay"?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

I don't see any problems - have you tried it?
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

VladSun wrote:I don't see any problems - have you tried it?
Yeah, this is the response I get:
HTTP/1.0 302 Moved Temporarily Location: https://www.linkpointcentral.com/lpc/servlet/lppay X-Cache: MISS from wc02.inet.mesa1.secureserver.net Connection: close 168
Are you familiar with link point?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

HTTPS (SSL) does not communicate on port 80 by default. It uses 443, if memory serves.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

feyd wrote:HTTPS (SSL) does not communicate on port 80 by default. It uses 443, if memory serves.
When I changed the port number:

Code: Select all

$socket = @fsockopen($url['host'], 443, $errno, $errstr) or die("Error: unable to open a socket connection with ".$url['host']."\n $errno: $errstr");
I get:
Error: unable to open a socket connection with http://www.linkpointcentral.com 110: Connection timed out
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Did you read the documentation for the function a little more on SSL?
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

feyd wrote:Did you read the documentation for the function a little more on SSL?
Which function, which documentation. I don't know of any SSL documentation, I guess now would be a good time to ask for some good resources.

But other then the port number does everything else look alright like it would send the data in the right format and get the full response?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

.... fsockopen()'s documentation states a few things about SSL pretty quick..
Post Reply