'),array('',''),$code)); function post($url, $post) { $to_encoding = CLIENT_ENCODING; $from_encoding = 'UTF-8'; /* URLを分解 */ $URL = parse_url($url); /* デフォルトのポートは80 */ if (!isset($URL['port'])) $URL['port'] = 80; /* リクエストライン */ $request = "POST ".$URL['path']." HTTP/1.0\r\n"; /* リクエストヘッダ */ $request .= "Host: ".$URL['host']."\r\n"; $request .= "User-Agent: PHP/".phpversion()."\r\n"; /* Basic認証用のヘッダ */ /* if (isset($URL['user']) && isset($URL['pass'])) { $request .= "Authorization: Basic ".base64_encode($URL['user'].":".$URL['pass'])."\r\n"; }*/ /* ヘッダを追加して末尾にURLエンコードしたデータを添付 */ if(empty($post)){ $post = array('dummy','dummy'); } while (list($name, $value) = each($post)) { if(is_array($value)){ $name = '_'.$name; $value = serialize($value); } $POST[] = $name."=".urlencode($value); } $postdata = implode("&", $POST); $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; $request .= "Content-Length: ".strlen($postdata)."\r\n"; $request .= "\r\n"; $request .= $postdata; /* WEBサーバへ接続 */ $fp = fsockopen($URL['host'], $URL['port']); /* 接続に失敗した時の処理 */ if (!$fp) { die("ERROR\n"); } /* 要求データ送信 */ fputs($fp, $request); /* 応答データ受信 */ $response = ""; while (!feof($fp)) { $response .= fgets($fp, 4096); } /* 接続を終了 */ fclose($fp); /* ヘッダ部分とボディ部分を分離 */ $DATA = split("\r\n\r\n", $response, 2); /* メッセージボディを出力 */ return mb_convert_encoding($DATA[1],$to_encoding,$from_encoding); } ?>