那么你可以使用CURL
/* Some params you wish to send */
$sEncodedParams = 'foo=Bar%20Baz&key=1234';
/* Create a new CURL Object */
$ch = curl_init();
/* Set the URL */
curl_setopt($ch, CURLOPT_URL, $sUrl);
/* Make CURL use POST */
curl_setopt($ch, CURLOPT_POST, true);
/* Add the POST-Data */
curl_setopt($ch, CURLOPT_POSTFIELDS, $sEncodedParams);
/* SET the Headers */
curl_setopt($ch, CURLOPT_HEADER, 0);
/* Execute the request */
curl_exec($ch);
/* Close CURL */
curl_close($ch);
您甚至可以使用类似这样的方法将响应返回到变量中
/* Tell CURL to return the response into a variable instead of echoing it */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
/* Save the response */
$sResponse = curl_exec($ch);
希望这可以帮助
问候
编辑:除了 SSL 支持(没有CURL
):
/* Timeout */
$iTimeout = 30;
/* EOL style */
$sEOL = "\r\n";
/* Some params you wish to send */
$sEncodedParams = 'foo=Bar%20Baz&key=1234';
/* Initialize the SSL-Socket */
$rSSLSocket = @fsockopen("ssl://www.domain.com", 443, $iError, $sError, $iTimeout);
/* Will contain the response data */
$sResponse = '';
/* If it worked */
if($rSSLSocket !== false) {
/* Put whatever you need here */
fputs($rSSLSocket, 'POST /path/here HTTP/1.0' . $sEOL);
fputs($rSSLSocket, 'Host: www.domain.com' . $sEOL);
fputs($rSSLSocket, 'Content-type: application/x-www-form-urlencoded' . $sEOL);
fputs($rSSLSocket, 'Content-Length: ' . strlen($sEncodedParams) . $sEOL);
fputs($rSSLSocket, 'Connection: close' . $sEOL . $sEOL);
fputs($rSSLSocket, $sEncodedParams);
while(!feof($rSSLSocket)) {
$sResponse .= @fgets($rSSLSocket, 2048);
}
fclose($rSSLSocket);
} else {
// ERROR
}
我希望这有帮助。但要小心,因为fsockopen
可能很棘手