仙台の山奥で自転車に乗ったり転んだり

愛車の GIOS でサイクリングしたりポタリングしたり、それをブログに記録してみたり。ロードバイクや自転車や坂のことを書いてみたり。ときたまプログラムのことを忘れないようにメモってみたり。

PHPで作ったPOSTリクエストするためのテスタ

HTTP_Clientでざっくり作ってみる。

<?php

/**
 * @use HTTP_Client
 */
require_once 'HTTP/Client.php';

// Request URL
$url = 'http://localhost/test.php';

// POST data
$post_data = '...POST Data...';

// Files
$files = array();

// Request header
$headers = array(
      'Host'          => 'hostname', 
      'User-Agent'    => 'PHP Tester', 
      'Content-Type'  => 'application/x-www-form-urlencoded', 
      'Connection'    => 'Close', 
      'Cache-Control' => 'no-cache', 
    );

$client   = new HTTP_Client;
$result   = $client->post($url, $post_data, true, $files, $headers);
$response = $client->currentResponse();

var_dump($result);
var_dump($response);