POST request only with http
I need to create a POST request with http_build_query . Following are my codes:
$uri_args = array (
'name' => 'Jack',
'surname' => 'Jackson',
'username' => 'jackson12',
'email' => 'Jack@mail.com',
);
$uri = http_build_query($uri_args);
header("Location: http://samplesite.com?$uri");
At the moment it generates a request like GET, but I need POST. Consider that I do not want to use curl, ... only http_build_query .
<?php
$data = array(
'name' => 'Jack',
'surname' => 'Jackson',
'username' => 'jackson12',
'email' => 'Jack@mail.com',
);
$query = http_build_query($data);
// create context
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded' . PHP_EOL,
'content' => $query,
),
));
// send request and collect data
$response = file_get_contents(
$target = "http://example.com/target.php",
$use_include_path = false,
$context);
//some actions with $response
//...
// redirect
header("Location: http://samplesite.com");
链接地址: http://www.djcxy.com/p/41098.html
上一篇: Servlet在doPost方法中获得GET和POST的参数
下一篇: POST请求只与http