Home > Uncategorized > HTTP POST using PHP

HTTP POST using PHP

$url = ‘https://posttestserver.com/post.php’;
$data = array(‘key1’ => ‘value1’, ‘key2’ => ‘value2’);

// use key ‘http’ even if you send the request to https://…
$options = array(
‘http’ => array(
‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”,
‘method’ => ‘POST’,
‘content’ => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo($result);

—- And the cool thing is that posttestserver.com lets you see what you posted to it. cool service!

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: