1$url = 'http://server.com/path';
2$data = array('key1' => 'value1', 'key2' => 'value2');
3
4// use key 'http' even if you send the request to https://...
5$options = array(
6 'http' => array(
7 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
8 'method' => 'POST',
9 'content' => http_build_query($data)
10 )
11);
12$context = stream_context_create($options);
13$result = file_get_contents($url, false, $context);
14if ($result === FALSE) { /* Handle error */ }
15
16var_dump($result);
17
1<?php
2//The url you wish to send the POST request to
3$url = $file_name;
4
5//The data you want to send via POST
6$fields = [
7 '__VIEWSTATE ' => $state,
8 '__EVENTVALIDATION' => $valid,
9 'btnSubmit' => 'Submit'
10];
11
12//url-ify the data for the POST
13$fields_string = http_build_query($fields);
14
15//open connection
16$ch = curl_init();
17
18//set the url, number of POST vars, POST data
19curl_setopt($ch,CURLOPT_URL, $url);
20curl_setopt($ch,CURLOPT_POST, true);
21curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
22
23//So that curl_exec returns the contents of the cURL; rather than echoing it
24curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
25
26//execute post
27$result = curl_exec($ch);
28echo $result;
29?>
30