Solved

How to create a post form, without using a form.(PERL)

Posted on 1997-12-07
3
135 Views
Last Modified: 2013-12-25
Here's where I'm at:

I have all the information a user wants submitted to a form, and now, using PERL, I need to create the correct headers and send them to an outside site.

For example:  I know the user wants to know the weather in Detroit, I want to pass information to the Weather Channel just as if it had come from the www.weather.com POST form in the first place.  

I have this working for GET forms, I just call the form-submit URL and ?append the variables.  I want to know how to do this for POST forms.

Can anyone please walk or pseudocode (Heck, or even show code!) me through this?

JMills99
0
Comment
Question by:jmills99
  • 2
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1831573
It looks like their POST form just directs you to another url, e.g.
http://www.weather.com/weather/us/cities/MI_Detroit.html
So couldn't you just send your user to that same url?

0
 
LVL 7

Accepted Solution

by:
faster earned 160 total points
ID: 1831574
You need two header fields:

Content_type: application/x-www-form-urlencoded\r\n
Content_length: XXX\r\n
\r\n
name1=val1&name2=val2

The entity body is something like the query string.  XXX is the size of the body, remember that you need an empty line before the body.

0
 
LVL 84

Expert Comment

by:ozo
ID: 1831575
#!/usr/bin/perl

$server = 'www.weather.com';
$document='/cgi-bin/uncgi/city_search.pl';
$content = 'go city&city_destination=boston';
$port = 80;

use Socket;
$tcp = getprotobyname('tcp');

socket(S, PF_INET, SOCK_STREAM, $tcp) || die "socket: $!";

if ($server =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {
    $addrs = pack('C4', split(/\./,$server));
}else{
    $addrs = (gethostbyname($server))[4];
}

$remote = sockaddr_in($port,inet_aton($server));
connect(S, $remote) or die "can't connect to $server because $!";

select(S); $| = 1;
select(STDOUT); $| = 1;

$request = "POST $document HTTP/1.0
User-Agent: LWP-request/1.20
Content-Length: ".length($content)."
Content-Type: application/x-www-form-urlencoded

";

print(S $request);
print(S $content);

$/ = "\r\n\r\n";
$_ = <S>;
print $_;

undef $/;
print <S> if( /Content-type:\s*text\// );
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to dynamically set the form action using jQuery.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question