我正在使用以下功能:
function createSocket($host, $script, $request, $method="POST", $port="8080") {
$request_length = strlen($request);
$output="";
$script .= "?$request";
//echo "host=".Middle_Tier;
$header = "$method $script HTTP/1.1\r\n";
$header .= "Host: $host\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: $request_length\r\n";
$header .= "Connection: close\r\n\r\n";
$header .= "$request\r\n";
$socket = fsockopen($host, $port, $errno, $errstr);
if ($socket) //if its open, then...
{
fputs($socket, $header); // send the details over
while(!feof($socket)) {
$output[] = fgets($socket); //get the results
}
return $output;
fclose($socket);
}
else {
return false;
}
}
$host = 'my host';
$script = 'path/to/my/function';
$request = "phone=$phone&city_id=$city_id";
$arr = createSocket($host, $script, $request, $method="POST", $port="8080");
我从目的地获得此结果:
$arr[9] = unavailable
当我打印时:
strlen($arr[9]);
输出 14 (即3个附加字符)
答案 0 :(得分:1)
您的代码存在一些问题。
HTTP/1.1
而不处理chunked encoding如果您不需要/想要任何花哨的HTTP 1.1功能,请改用HTTP / 1.0。