Create POST requests with PHP Headers
Create POST requests with PHP Headers
If for some reason you need to create a POST request using PHP headers, this is the way to go:
1
2
3
4
5
6
7
8
9
10
11
12
13
| //The domain of your website$host = 'www.yoursite.com';//The path you want to send the request to: (www.yoursite.com/user/add)$path = "/user/add";//Encode the POST params you want to send$data = urlencode("username=John&surname=smith&phone=0856474633");header("POST $path HTTP/1.1\r\n" );header("Host: $host\r\n" );header("Content-type: application/x-www-form-urlencoded; charset=UTF-8\r\n" );header("Content-length: " . strlen($data) . "\r\n" );header("Connection: close\r\n\r\n" );header($data); |
Comments