I have a client-application that uses a socket to post some data to a
server-application. The following piece of code in the client takes care of
the posting:
$sock = fsockopen("www.majstro.com", 80, $errno, $errstr, 30);
if ($sock)
{
$data = 'a=0&b=1';
fputs($sock, "POST /Web/Majstro/SD_Server.php HTTP/1.0\r\n");
fputs($sock, "Host: www.majstro.com\r\n");
fputs($sock, "Accept: */*\r\n");
fputs($sock, "Content-type: application/x-www-url-encoded\r\n");
fputs($sock, "Content-length: " . strlen($data) . "\r\n\r\n");
fputs($sock, "$data\r\n");
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n";
$body = "";
while (!feof($sock))
$body .= fgets($sock, 4096);
fclose($sock);
return $body;
}
My problem is that SD_Server.php is indeed called, but that it is unable to
extract the parameters from the HTTP-header. They are not present in $_POST,
and count($HTTP_POST_VARS) returns the value 0. On the other hand,
$_SERVER['CONTENT_LENGTH'] contains the value 7, which is exactly the string
length of "a=0&b=1". So, it seems that the data is present in the header,
but for some reason PHP just cannot parse it.
I have run out of ideas to make this work. Has anybody here a suggestion? It
might work if I use the get method instead of the post method, but I very
much like to know what is wrong with this code.
Gerard van Wilgen
-- www.majstro.com (On-line translation dictionary / Enreta tradukvortaro) www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga
tradukvortaro por Windows) 8 4500
> fputs($sock, "Content-length: " . strlen($data) . "\r\n\r\n");
too many \r\n\r\n
--
Mike Bradley http://www.gzentools.com -- free online php tools
"Gerard van Wilgen" <gv********@planet.nl> wrote in message
news:bv**********@reader10.wxs.nl... I have a client-application that uses a socket to post some data to a server-application. The following piece of code in the client takes care
of the posting:
$sock = fsockopen("www.majstro.com", 80, $errno, $errstr, 30); if ($sock) { $data = 'a=0&b=1'; fputs($sock, "POST /Web/Majstro/SD_Server.php HTTP/1.0\r\n"); fputs($sock, "Host: www.majstro.com\r\n"); fputs($sock, "Accept: */*\r\n"); fputs($sock, "Content-type: application/x-www-url-encoded\r\n"); fputs($sock, "Content-length: " . strlen($data) . "\r\n\r\n"); fputs($sock, "$data\r\n"); $headers = ""; while ($str = trim(fgets($sock, 4096))) $headers .= "$str\n"; $body = ""; while (!feof($sock)) $body .= fgets($sock, 4096); fclose($sock); return $body; }
My problem is that SD_Server.php is indeed called, but that it is unable
to extract the parameters from the HTTP-header. They are not present in
$_POST, and count($HTTP_POST_VARS) returns the value 0. On the other hand, $_SERVER['CONTENT_LENGTH'] contains the value 7, which is exactly the
string length of "a=0&b=1". So, it seems that the data is present in the header, but for some reason PHP just cannot parse it.
I have run out of ideas to make this work. Has anybody here a suggestion?
It might work if I use the get method instead of the post method, but I very much like to know what is wrong with this code.
Gerard van Wilgen -- www.majstro.com (On-line translation dictionary / Enreta tradukvortaro) www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga tradukvortaro por Windows)
"CountScubula" <me@scantek.hotmail.com> wrote in message
news:UU*****************@newssvr29.news.prodigy.co m... fputs($sock, "Content-length: " . strlen($data) . "\r\n\r\n");
too many \r\n\r\n
I do not think so. Every example that I have seen had an empty line between
the headers and the data, as is required by the HTTP-specs. Anyway, I have
tried it without an empty line, just to be sure. and that only resulted in
an "invalid header" message.
Gerard van Wilgen
-- www.majstro.com (On-line translation dictionary / Enreta tradukvortaro) www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga
tradukvortaro por Windows)
"Gerard van Wilgen" <gv********@planet.nl> wrote in message
news:bv**********@reader08.wxs.nl... "CountScubula" <me@scantek.hotmail.com> wrote in message news:UU*****************@newssvr29.news.prodigy.co m... fputs($sock, "Content-length: " . strlen($data) . "\r\n\r\n"); too many \r\n\r\n
I do not think so. Every example that I have seen had an empty line
between the headers and the data, as is required by the HTTP-specs. Anyway, I have tried it without an empty line, just to be sure. and that only resulted in an "invalid header" message.
Gerard van Wilgen -- www.majstro.com (On-line translation dictionary / Enreta tradukvortaro) www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga tradukvortaro por Windows)
Ok, no problem, I do not know if your posting vars or data, to do vars,
there is no blank line, to post data, yes there is.
data: content-length + blank line + data
vars: no content-length + no blank line + vars + then blanks lines
read a little closer, and grab a packet sniffer and watch the packets before
you try and create a packet without even knowing what it looks like.
here is a super simple one: http://www.gzentools.com/sockview.php
--
Mike Bradley http://www.gzentools.com -- free online php tools
You got an extra dash in the content type. It's
"application/x-www-form-urlencoded"
:-)
Uzytkownik "Gerard van Wilgen" <gv********@planet.nl> napisal w wiadomosci
news:bv**********@reader10.wxs.nl... I have a client-application that uses a socket to post some data to a server-application. The following piece of code in the client takes care
of the posting:
$sock = fsockopen("www.majstro.com", 80, $errno, $errstr, 30); if ($sock) { $data = 'a=0&b=1'; fputs($sock, "POST /Web/Majstro/SD_Server.php HTTP/1.0\r\n"); fputs($sock, "Host: www.majstro.com\r\n"); fputs($sock, "Accept: */*\r\n"); fputs($sock, "Content-type: application/x-www-url-encoded\r\n"); fputs($sock, "Content-length: " . strlen($data) . "\r\n\r\n"); fputs($sock, "$data\r\n"); $headers = ""; while ($str = trim(fgets($sock, 4096))) $headers .= "$str\n"; $body = ""; while (!feof($sock)) $body .= fgets($sock, 4096); fclose($sock); return $body; }
My problem is that SD_Server.php is indeed called, but that it is unable
to extract the parameters from the HTTP-header. They are not present in
$_POST, and count($HTTP_POST_VARS) returns the value 0. On the other hand, $_SERVER['CONTENT_LENGTH'] contains the value 7, which is exactly the
string length of "a=0&b=1". So, it seems that the data is present in the header, but for some reason PHP just cannot parse it.
I have run out of ideas to make this work. Has anybody here a suggestion?
It might work if I use the get method instead of the post method, but I very much like to know what is wrong with this code.
Gerard van Wilgen -- www.majstro.com (On-line translation dictionary / Enreta tradukvortaro) www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga tradukvortaro por Windows)
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<0P********************@comcast.com>... You got an extra dash in the content type. It's "application/x-www-form-urlencoded"
:-)
Right, I think modifying content-type will solve your problem.
"Rahul Anand" <ra************@rediffmail.com> wrote in message
news:62**************************@posting.google.c om... "Chung Leong" <ch***********@hotmail.com> wrote in message
news:<0P********************@comcast.com>... You got an extra dash in the content type. It's "application/x-www-form-urlencoded"
:-)
Right, I think modifying content-type will solve your problem.
The content-type was indeed incorrect. Unfortunately, changing it did not
change anything.
Gerard van Wilgen
-- www.majstro.com (On-line translation dictionary / Enreta tradukvortaro) www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga
tradukvortaro por Windows)
"Gerard van Wilgen" <gv********@planet.nl> wrote in message
news:bv*********@reader11.wxs.nl... "Rahul Anand" <ra************@rediffmail.com> wrote in message news:62**************************@posting.google.c om... "Chung Leong" <ch***********@hotmail.com> wrote in message news:<0P********************@comcast.com>... You got an extra dash in the content type. It's "application/x-www-form-urlencoded"
:-)
Right, I think modifying content-type will solve your problem.
The content-type was indeed incorrect. Unfortunately, changing it did not change anything.
Gerard van Wilgen -- www.majstro.com (On-line translation dictionary / Enreta tradukvortaro) www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga tradukvortaro por Windows)
here is a capture from a packet sniffer, notice no blank line:
POST http://www-1.gzentools.com/browserchk.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword,
application/x-shockwave-flash, */*
Referer: http://www-1.gzentools.com/browserchk.php
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
Connection: Close
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Host: www-1.gzentools.com
Content-Length: 67
Pragma: no-cache
Cookie: sm=browser-server
field_textbox=test+post+data&field_hidden=This+is+ hidden+field+data
--
Mike Bradley http://www.gzentools.com -- free online php tools
"CountScubula" <me@scantek.hotmail.com> wrote in message
news:2F*******************@newssvr27.news.prodigy. com... "Gerard van Wilgen" <gv********@planet.nl> wrote in message news:bv*********@reader11.wxs.nl... "Rahul Anand" <ra************@rediffmail.com> wrote in message news:62**************************@posting.google.c om... "Chung Leong" <ch***********@hotmail.com> wrote in message news:<0P********************@comcast.com>... > You got an extra dash in the content type. It's > "application/x-www-form-urlencoded" > > :-) >
Right, I think modifying content-type will solve your problem.
The content-type was indeed incorrect. Unfortunately, changing it did
not change anything.
Gerard van Wilgen -- www.majstro.com (On-line translation dictionary / Enreta tradukvortaro) www.travlang.com/Ergane (Free translation dictionary for Windows /
Senpaga tradukvortaro por Windows)
here is a capture from a packet sniffer, notice no blank line:
POST http://www-1.gzentools.com/browserchk.php HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel,
application/msword, application/x-shockwave-flash, */* Referer: http://www-1.gzentools.com/browserchk.php Accept-Language: en-us Content-Type: application/x-www-form-urlencoded Connection: Close User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Host: www-1.gzentools.com Content-Length: 67 Pragma: no-cache Cookie: sm=browser-server field_textbox=test+post+data&field_hidden=This+is+ hidden+field+data
I see, but perhaps the packet sniffer suppressed it, or maybe the server
application is smart enough to figure out that the last part must be the
data.
Anyway, I just found out that correcting the Content-Type solved the problem
after all (At first I accidentally used a wrong parameter string when
testing that solution).
Thanks to everyone in the newsgroup who helped me solving this!
Gerard van Wilgen
-- www.majstro.com (On-line translation dictionary / Enreta tradukvortaro) www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga
tradukvortaro por Windows) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Spud |
last post by:
<?php
// pullpage function by Nick bouton http://www.nickbouton.com/.
$CustomerID = "IDHERE";
$method = "POST";
$host = "xml.mydata.com";
$usepath = "/xml.asp";
//print all vars in an...
|
by: Alec |
last post by:
Hi All,
I have recently built a site using PHP and MySQL, and started to
implement a basic forum into it. However, the form to post messages
doesnt do what I want it to. If there is no user...
|
by: Thomas Scheiderich |
last post by:
I am trying to understand Session variables and ran into a question on
how they work with data that is passed.
I have an HTM file that calls an ASP file and sends the name either by
GET or POST....
|
by: glenn |
last post by:
I am use to programming in php and the way session and post vars are past
from fields on one page through to the post page automatically where I can
get to their values easily to write to a...
|
by: c676228 |
last post by:
Hi,
I am new to this discussion forum. I started to post questions on this forum
since this Jan. and got many good responses and I am very appreciated to
those who are willing to help with their...
|
by: Brybot |
last post by:
I am trying to allow HTTP POST file uploads to my web service.
Currently I have it working perfectly for a SOAP/XML request reading
in a byte using MemoryStream/FileStream but I cannot figure out...
|
by: Peter Michaux |
last post by:
Hi,
All Ajax libraries I've read use encodeURIComponent() on the name-
value pairs extracted from forms before POST ing the result to the
server with and xmlhttprequest. I can understand why...
|
by: UKuser |
last post by:
Hi,
I'm not sure if this can be done as I've searched the web and this
forum.
I am using an online merchant provider and I must post certain
variables to their webforms through a form on my...
|
by: Jag |
last post by:
Hi
I am facing a strange issue. I have 3 ASP pages in the default
website
1. auth.aspx
<html>
<body>
|
by: CindyH |
last post by:
Hi
Trying to get this code to work for http xml post.
I need the post to be xml (doc.outerxml) sent in single key name as stream.
The following is the post code and code for receiving the request....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |