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.

<?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);

?>

    What's the URL for the original form that you're trying to simulate?

      http://a836-acris.nyc.gov/Scripts/DocSearch.dll/BBL

      The cURL got a 405 not Allowed error

      <?php
      
      $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
      
      ?>

        Oh yeah it needs a cookie from there maybe? Click on "Begin using Acris" in the middle. Then you can go to the url i provided.

          The form on that page POST's information to '/Scripts/DocSearch.dll/BBLResult' after setting some hidden fields up via Javascript. Doesn't seem like they meant for you to use a script to access their website and post data, so I'm guessing doing so isn't allowed.

          If they did want you to do so, they'd give you an API to use that designed for sending/receiving information to/from another computer, not a human (e.g. a form with Javascript).

            I know its done all of the time and they limit bandwidth.

              I would still recommend contacting them and asking if there is a public API you should be using, rather than simulating a form submission that involves hidden Javascript fields and whatnot. Otherwise, you're left with tracing through the go_Submit() Javascript function in order to properly simulate what the form looks like after you click the submit button.

                I have looked at BBL.js which is referenced. Where do i research how to trace g0_Submit?

                  twittoris wrote:

                  Where do i research how to trace g0_Submit?

                  I don't think there's any tutorial on how to do something like that, it's really just using your logic and following through the code. Go through the go_submit() function line-by-line (or statement-by-statement, if each isn't separated by a line break :p) and see what changes are made to the form (if any).

                    bradgrafelman wrote:

                    I would still recommend contacting them and asking if there is a public API you should be using, rather than simulating a form submission that involves hidden Javascript fields and whatnot.

                    Indeed there is; they even supply a link to the relevant page where it warns about the bandwidth cap and automated querying.

                      Write a Reply...