可以使用以下函数来实现:
function posttohost($url, $data) {
$url = parse_url($url);
if (!$url) return "couldnt parse url";
if (!isset($url[port])) { $url[port] = ""; }
if (!isset($url[query])) { $url[query] = ""; }
$encoded = "";
while (list($k,$v) = each($data)) {
$encoded .= ($encoded ? "&" : "");
$encoded .= rawurlencode($k)."=".rawurlencode($v);
}
$fp = fsockopen($url[host], $url[port] ? $url[port] : 80);
if (!$fp) return "Failed to open socket to $url[host]";
fputs($fp, sprintf("POST %s%s%s HTTP/1.0
", $url[path], $url[query] ? "?" : "", $url[query]));
fputs($fp, "Host: $url[host]
");
fputs($fp, "Content-type: application/x-www-form-urlencoded
");
fputs($fp, "Content-length: " . strlen($encoded) . "
");
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号