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.

 

 

 

Link to comment
Share on other sites

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

 

 

?>

Link to comment
Share on other sites

$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

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.