使用php POST _viewstate

Hi I'm trying to send post values using a PHP script to an external website and get the result. My code is as follows

$postdata = http_build_query(
    array(
        'drpservice' => 091,
        'drpdirection' => 1,
        'drpbusstop' => 18051
    )
);

$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($url, false, $context);

echo $result;

However, it won't return the required results unless I can manage to send in the hidden _VIEWSTATE value. Anyone able to help?

You need to first get the form page using a GET request, and then you can parse the page to get the _VIEWSTATE value using a regular expression.

Then when doing the POST pass the value you got for it.