Topic: fetching a form that requires POST using FPUTS (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=28027" title="Pages that link to Topic: fetching a form that requires POST using FPUTS (Page 1 of 1)" rel="nofollow" >Topic: fetching a form that requires POST using FPUTS <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-02-2006 23:15

Greets!

I'm using fputs to try and submit a form via POST and have it display the results. I can get it to somewhat work, but the results of the form are not the same as if I run the form natively.

A working example: http://www.state.mi.us/mdoc/asp/otis2.asp use "Kevorkian" for last name, "Jack" for first name, and "All" for race and Offender Status. You get one result (the correct one for Dr. Death).

My example: http://michiganoffenders.org/dev/otis_check.php, which automatically supplies the values. I don't get a valid result. http://michiganoffenders.org/dev/otis_check.phps is the source. I can't see what I'm doing wrong, but I admit my skills with fputs are limited, especially when using POST (GET won't work on this form).

Once I can get a valid return, I can further process $data to yield the info I need. This will ultimately be part of a cron job process.

And sadly, XML won't be available from the state for some time.... :-(

I know Mr. Max is the master at this, but he's MIA from this site.

DmS
Maniac (V) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 06-03-2006 00:22

Never used fputs for stuff like this, however, we do pass simulated form data through post to remote servers all the time at work.
We always use cUrl and it works like charm.

Unfortunately our code is part of a lib that I cannot post publicly, but the basics can be found anywhere, all you need is to have curl support in your php install, tutorials and examplecode can be found everywhere.
/D

{cell 260} {Blog}
-{" Computer:
?As a Quantum Supercomputer I take advantage of Zeno?s paradox?
C: ?Imagine a photon that must travel from A to B. The photon travels half the distance to B. From its new location it travels half the new distance. And again, it travels half that new distance.?
C: ?It continually works to get to B but it never arrives.?
Human: ?So you keep getting closer to finishing your task but never actually do??
C: ?Hey, coders make a living doing that??
?}-

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-03-2006 11:19

yeah, curl is the easier way to go.

Otherwise read up on the rfc->2616 (HTTP).

oh, and here's a quick simple 'post by hand snippet' I had floating around.
(slightly adjusted in this very post window to actually not require a whole surrounding object)

code:
function makeFunnyPost ( $strPath, $strHostName, $arrData )
{	
                  $strPostData = '';
                  foreach ( $arrData as $strKey => $strValue ) 
                 {
                      if ($strPostData)
                          $strPostData .= '&';
                      $strPostData .= urlencode ( $strKey ) . '='. urlencode ( $strValue);
                 } 
		$strRequest = 
			"POST ". $strPath. " HTTP/1.0\r\n".	
			"Host: ". $strHostName . "\r\n".	
			"Content-Type: application/x-www-form-urlencoded\r\n".
			"Content-length: ". strlen($strPostData). "\r\n".
			"\r\n".
			$strPostData. "\r\n";				
		$fh = fsockopen($strHostName,80);	
		if ($fh)
		{	
			fwrite($fh,$strRequest);
			$strResponse = '';
			while (!feof($fh))
			{
				$strResponse .= fread($fh,2048);
			}
			fclose($fh);
			$strResponse = trim(substr($strResponse,strpos($strResponse,"\r\n\r\n"))); //cut of http header.
			return $strResponse;
		}
		else
			return False;
	}



so long,

->Tyberius Prime

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-22-2006 04:53

Alright - I'm not having much luck with this.

example http://michiganoffenders.org/dev/otis_check_new2.php
source http://michiganoffenders.org/dev/otis_check_new2.phps

results should be the same as if you go to http://www.state.mi.us/mdoc/asp/otis2.asp use "Kevorkian" for last name, "Jack" for first name, and "All" for race and Offender Status. You get one result.

A big black pill to whomever points me in the write direction.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-22-2006 07:15

Case Sensitive Option Values.

code:
<?php
$url="http://www.state.mi.us/mdoc/asp/otis2results.asp";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
$strPostFields = "last=Kevorkian&first=Jack&gender=Either&race=All&status=All";
curl_setopt ($ch, CURLOPT_POSTFIELDS, $strPostFields );
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec ($ch);
curl_close ($ch);
echo $content;
?>

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-22-2006 14:09

Hmmm.... interesting. Well, that works. Now I just gotta find out why it takes 28 seconds to run. Thanks, TP!

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-22-2006 17:10

Try setting some browser like headers... I'd start with User-Agent

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-22-2006 17:56

Okay - will do. Interesting in that if I put the script into a loop, it takes 25+ seconds to do the first one, but only a second or two to do ALL the rest combined. Everytime.

Thanks for the tip. I'll try that.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-22-2006 21:16

In that case, it could easily be the name lookup for the host.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 06-23-2006 02:59

I'm trying to troubleshoot now.... everything else is working great, and it's slowly looping through ~20,000 queries....



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu