Solved

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

Posted on 1997-12-07
3
138 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

752 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