【发布时间】:2014-06-23 00:32:33
【问题描述】:
我必须编写一些 PHP 代码来向外部服务器发出 post 请求,并从服务器所有者那里得到两个不同的示例,一个在 URL 中使用“ssl://”,另一个使用“https://”。
它们可以互换使用吗?这将记录在哪里?谢谢!
编辑以包含 PHP 代码(不知道为什么我不能正确格式化代码,如果有人可以帮助解释如何将初始注释合并到代码块中):
// make a http post request to an external server
function httpPost($host, $usepath, $postdata = "") {
$fp = fsockopen($host, 443, $errno, $errstr, 60);
if( !$fp ) {
print "$errstr ($errno)<br>\n";
}
else {
fwrite( $fp, "POST $usepath HTTP/1.0\n");
$strlength = strlen( $postdata );
fwrite( $fp, "Content-type: application/x-www-form-urlencoded\n" );
fwrite( $fp, "Content-length: ".$strlength."\n\n" );
fwrite( $fp, $postdata."\n\n" );
$output = "";
while( !feof( $fp ) ) {
$output .= fgets( $fp, 1024);
}
fclose( $fp);
}
return $output;
}
【问题讨论】:
-
我可以编辑您的问题并为您设置格式,但由于您似乎对 SO 不熟悉,您不妨尝试一下:编辑时选择整个代码区域,然后单击 @987654322 @ 图标。这应该在每个选定的行前插入 4 个空格(并触发代码格式化)。
-
@Bruno - 确实,这就是我想要的,自己动手做。现在看起来好多了。