Jump to content

Posting with file_get_contents Need Some Pointers


twittoris

Recommended Posts

I am trying to grab the contents from a form result. However, I keep getting the following message.

 

Warning: file_get_contents(http://a836-acris.nyc.gov/docsearch.dll/BBL) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 405 Method not allowed in /home/content/e/m/p/empireestate/html/acris.php on line 23

 

This is my first draft so i know its not working but was wondering if someone can give me a few pointers.

 

 

 

Forgot to attach the code:

 

<?php

$URL = 'http://a836-acris.nyc.gov/Scripts/DocSearch.dll/BBL';

 

$postdata = http_build_query(

    array(

        'hid_borough' => '1',

        'hid_block' => '995',

'hid_lot' => '1',

 

    )

);

 

$opts = array('http' =>

    array(

        'method'  => 'POST',

        'header'  => 'Content-type: application/x-www-form-urlencoded',

        'content' => $postdata

    )

);

 

$context  = stream_context_create($opts);

 

$result = file_get_contents('http://a836-acris.nyc.gov/docsearch.dll/BBL', false, $context);

 

 

?>

$post_fields = array(

 

  'g.hid_borough.value' => $_POST['1'],

  'g.hid_block.value ' => $_POST['995'],

  'g.hid_lot.value  ' => $_POST['1'],

 

);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://a836-acris.nyc.gov/Scripts/DocSearch.dll/BBLResult'); // set the remote url

curl_setopt($ch, CURLOPT_POST, 1); // yes we are posting

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); // this is our POST data

curl_setopt($ch, CURLOPT_HEADER, 0); // no headers in output

curl_setopt($ch, CURLOPT_VERBOSE, 1); // verbose output, good for debugging

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// $ch will return the results of your POST when you execute

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); // the remote sites often check for a known user agent

 

$result = curl_exec ($ch);

curl_close($ch);

echo($ch);

print $result

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.