Forum Moderators: coopster & phranque

Message Too Old, No Replies

POST ok on cgi but not php

         

blakmonk

7:59 pm on May 31, 2004 (gmt 0)

10+ Year Member



Hi,

I'm having this weird issue. With a cgi-script I wrote this perl script that uses IO::Socket::SSL or IO::Socket::INET depending on if I access a http or https url.

With this script I POST information to another script. The information posted is quite big sometimes, 4,8 sometimes 16k, so GET is out of the question.

My script works fine when I post the informationto a perl script. But then the target script at the other end is a .php script, the .php script receives nothing, I mean it does not receive the variables nor the values.

What could I be missing?

Basically what the script does (in http cases ) is :

- open a socket to host:80
- then send the following headers :
POST $CgiName HTTP/1.0
Host: $HostName
Content-Type: text/xml; charset=utf-8
Content-Length: $Length\n";

$Data
<the wait for answer or timemout>

For https, its basically the same thing instead I open the socket with IO::Socket::SSL.

The data is in this form :

var1=val1&var2=val2&var3=val3

Any ideas?

BlakMonk

[edited by: jatar_k at 8:54 pm (utc) on May 31, 2004]
[edit reason] removed url [/edit]

MichaelBluejay

10:20 pm on May 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is just a wild, wild guess since I'm not familiar with posting or sockets, but are you sure you don't need two \n's after Content-length? I found out that my mail wasn't sending because I only had one of those instead of two, so maybe this is a similar thing.

blakmonk

12:33 am on Jun 1, 2004 (gmt 0)

10+ Year Member



The \n after $Length is a typo.

This is what is sent to the webserver:

POST $CgiName HTTP/1.0
Host: $HostName
Content-Type: text/xml; charset=utf-8
Content-Length: $Length

$Data

VectorJ

3:20 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



The text/xml header seems to be inconsistent with the format of the data you're sending... maybe that causes a problem in PHP while Perl recognizes the data format as text/html.

blakmonk

5:41 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



What Content-type: to you suggest I put?

remember, perl scripts take it no problem.

VectorJ

5:58 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



I would try using Content-type: text/html rather than Content-type: text/xml.

If that's not the problem, you could try using the WWW::Mechanize module to handle this for you.

blakmonk

6:22 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



Hi

I tried putting the text/html, same result. but xml is what I'm sending to the other server.

The $Data contains stuff like

x=<data><stuff>Yohoo</stuff></data>

What is the mechanize supposed to do?

Blakmonk

VectorJ

6:39 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



WWW:Mechanize just automates a number of browser-like functions, one of which is posting form data to a cgi. If there are any syntax errors in the way that you're posting data to the cgi, Mechanize ought to take care of them.

Is it possible that the server running the php script is blocking posts from your script (either by IP or some value included in the form data)? If you have access to that server, a look at the error logs may help also.

blakmonk

6:58 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



I see...

I sniffed request going to the web server with normal forms... turns out the header that is requested is

Content-Type: application/x-www-form-urlencoded

That solved my problem.

VectorJ,
thank you soo mych for your time.

</BlakMonk>