Http Posts
Moderator: General Moderators
I already stated that I can not use the port on my server to connect to a remote server, thus I can not use cURL methods. My only option is to make a post request.In essence, the question would be: Does your ISP allow you (the useraccount that executes the php script) to make an outgoing connection to (server, port)?
Are you sure about this? Because even with fskopen you need a local port to be opened ... That is the way Internet works 
Most of the hosting providers would refuse new connections *TO* their servers (except their service ports), but would allow outgoing connection and the incoming packets which are realated to this connection.
Most of the hosting providers would refuse new connections *TO* their servers (except their service ports), but would allow outgoing connection and the incoming packets which are realated to this connection.
There are 10 types of people in this world, those who understand binary and those who don't
I don't mean to argue with you but it's a bit confusing. Didn't you say "Generally - no, you don't need." in response to my post prior? And doesn't "Generally - no, you don't need." mean I don't need to open a port, but now you say I do? Or is it just a misunderstanding? You thought that the port of mine is already open and I don't need to open it so you said "Generally - no, you don't need.", rather then what I really meant which is that my port isn't open and I'm not authorized to open it.VladSun wrote:Are you sure about this? Because even with fskopen you need a local port to be opened ... That is the way Internet works
And if all posts to a server need to open a port in order to interact than who's port is being opened when ajax or an html form makes a request? Is it the clients ports that are both connecting? And more importantly, which port umber is being used, to be specific? The usual port 80 is fine, it's just port number 1129 that I'm having trouble with.
Also is a socket just a connection between two ports?
Okay I think I'm getting sidetracked on my original question.
So can someone explain to me what this script does line-by-line:
Code: Select all
// Request
$request = "POST /path HTTP/1.0\r\n"
. "Host: domain.tld\r\n"
. "Content-Type: application/x-www-form-urlencoded;\r\n"
. "Content-Length: " . strlen($dataToPost) . "\r\n"
. "\r\n"
. $dataToPost;
$fs = @fsockopen($host, $port, $errno, $errstr, 10);
fwrite($fs, $request);
// Response
$response = '';
while (!feof($fs)) {
$response .= fgets($fs, 1160);
}
fclose($fs);
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
In my understanding (as network admin) this mean: Do I need to call my hosting support and inform them that you want to make some outgoing connections so they have to change the server firewall settings to allow you. In short:JellyFish wrote:Does this mean that I don't need a port open for my server?
to open a port === to make a port not filtered by the firewall
The second part of my post you are quotting was an explanation for what I'd written above:JellyFish wrote: I don't mean to argue with you but it's a bit confusing. Didn't you say "Generally - no, you don't need." in response to my post prior? And doesn't "Generally - no, you don't need." mean I don't need to open a port, but now you say I do? Or is it just a misunderstanding? You thought that the port of mine is already open and I don't need to open it so you said "Generally - no, you don't need.", rather then what I really meant which is that my port isn't open and I'm not authorized to open it.![]()
".... Most of the hosting providers would refuse new connections *TO* their servers (except their service ports), but would allow outgoing connection and the incoming packets which are realated to this connection ..."
Exactly!JellyFish wrote: And if all posts to a server need to open a port in order to interact ...
While you are browsing in you favorite browser type in the command prompt/console:JellyFish wrote: ... than who's port is being opened when ajax or an html form makes a request?
netstat -n (windows)
or
netstat -ntp (Linux)
If you are sending HTTP request, by default the destination port is 80, and the source port (that's the port which gets opened in your understanding) is usually above 1024 and it must be a free port (i.e. not used by any other process at the local machine). So, you cannot say that it would always be 1129.JellyFish wrote: Is it the clients ports that are both connecting? And more importantly, which port umber is being used, to be specific? The usual port 80 is fine, it's just port number 1129 that I'm having trouble with.
JellyFish wrote:
Also is a socket just a connection between two ports?![]()
SOCKET
(1) In UNIX and some other operating systems, a software object that connects an application to a network protocol. In UNIX, for example, a program can send and receive TCP/IP messages by opening a socket and reading and writing data to and from the socket. This simplifies program development because the programmer need only worry about manipulating the socket and can rely on the operating system to actually transport messages across the network correctly. Note that a socket in this sense is completely soft - it's a software object, not a physical component.
There are 10 types of people in this world, those who understand binary and those who don't
Woaw!!! Wowy wow wow wowww! This clears sooooooo many things UP! Where in the world did you find that description?!?!VladSun wrote:SOCKETJellyFish wrote:Does this mean that I don't need a port open for my server?
(1) In UNIX and some other operating systems, a software object that connects an application to a network protocol. In UNIX, for example, a program can send and receive TCP/IP messages by opening a socket and reading and writing data to and from the socket. This simplifies program development because the programmer need only worry about manipulating the socket and can rely on the operating system to actually transport messages across the network correctly. Note that a socket in this sense is completely soft - it's a software object, not a physical component.
It makes so much sense now. A socket is like a file, that you can write to. And this allows you to communicate with another machine on a network! Also, at the end of the description it clarifies that a socket is soft, completely, it's just amazing! Really, I'm not kidding. I know that I asked myself at least once"Is a socket a wire of some kind?" but no, it ain't.
The epiphany that I get from that description also makes me understand what fsockopen does too! It's like a file function that makes a file on the remote server(the machine other then the requester) and returns a resource pointer of that file and allows me to execute other filesystem functions on that resource, like write to it, read it and what not. Am I figuring it out, or am I way off?
First Script:
Second Script:
Error
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']);
fwrite($socket, $request);
// Response
$response = '';
while (!feof($socket)) {
$response .= fgets($socket, 1160);
}
fclose($socket);
return $response;
}
?>Code: Select all
$transaction = HttpRequest("https://www.linkpointcentral.com/lpc/servlet/lppay", $myorder);What am I missing? An argument for fsockopen? All the other parameters other then host where optional.Warning: fwrite(): supplied argument is not a valid stream resource in /home/content/t/r/a/tradingtresure/html/lib/http.php on line 20
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
Warning: feof(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in /home/content/**************/html/lib/http.php on line 25
ETC...
Last edited by JellyFish on Sat Aug 18, 2007 11:30 am, edited 3 times in total.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Same thing...superdezign wrote:Take error suppression of of fsockopen and see what you get.
EDIT:
I changed the line to:
Code: Select all
$socket = fsockopen($url['host']) or die("Error: unable to open a socket connection.");
Code: Select all
$socket = @fsockopen($url['host']) or die('Cannot open the host '.$url['host']);- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
JellyFish wrote: changed the line to:
And I get the death.Code: Select all
$socket = fsockopen($url['host']) or die("Error: unable to open a socket connection.");
Make use of &$errno and &$errstr to see the actual failure.PHP Manual wrote:fsockopen ( string $hostname [, int $port [, int &$errno [, string &$errstr [, float $timeout]]]] )
Changed it to spades and got:
Spades:Error: unable to open a socket connection with http://www.linkpointcentral.com
Code: Select all
$socket = @fsockopen($url['host']) or die('Error: unable to open a socket connection with '.$url['host']);
... Wait, you use linkpoint? Okay, well they have an API, as you might know, that allows you to use cURL methods and what-not. But I wasn't able to use the API because of my server.miro_igov wrote:So you can't connect. Now add in the die( ............ 'The error is: '.$errstr);
Edit:Especially for linkpoint i will prefer to use cURL.
But anyways, I don't understand what you mean by this: die( ............ 'The error is: '.$errstr);. I didn't get that.