473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Post-problem

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)

Jul 17 '05 #1
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)

Jul 17 '05 #2

"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)


Jul 17 '05 #3
"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
Jul 17 '05 #4
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)

Jul 17 '05 #5
"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.
Jul 17 '05 #6

"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)

Jul 17 '05 #7
"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
Jul 17 '05 #8

"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)

Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
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...
1
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...
15
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....
10
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...
9
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...
6
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...
10
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...
56
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...
3
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>
9
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....
0
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
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...
1
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)...
0
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...
0
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....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.