Solved

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

Posted on 1997-12-07
3
134 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now