Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

760 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

20 Experts available now in Live!

Get 1:1 Help Now