发送带有 x-amf (Flash) 请求标头的 POST 请求
我正在尝试重现使用 PHP 从 WireShark 捕获的 POST 请求。这个POST请求是由Flash(.swf)对象发送的,因此配置标头有点复杂。
它最终没有打印出任何东西,所以 PHP 代码一定有什么问题,我看不到。
以下是 WireShark 捕获的内容:
POST /engine/ HTTP/1.1\r\n
Host: abcdef.com\r\n
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
Accept-Language: en-us,en;q=0.5\r\n
Accept-Encoding: gzip, deflate\r\n
Accept-Charset: UTF-8,*\r\n
Keep-Alive: 115\r\n
Connection: keep-alive\r\n
Cookie: __utma=77520967.190998754.1302600802.1302605710.1302693085.3; __utmz=77520967.1302600802.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); PHPSESSID=vqtt7v2l5h10nd06fdsuii49e0; __utmc=77520967
Referer: http://abcdef.com/v2.swf\r\n\r\n
Referer: http://abcdef.com/v2.swf\r\n
Content-Type: application/x-amf\r\n
Content-Length: 50\r\n
\r\n
这是 PHP 代码 with info.txt 由十六进制编辑器编写,所有信息都是正确的(即 50 个字节,WireShark 捕获的精确十六进制内容)
// Get cookie
$ch = curl_init('http://abcdef.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
preg_match('/^Set-Cookie: (.*?);/m', curl_exec($ch), $m);
// Read x-amf data
$fileHandle = fopen("info.txt", "rb");
$postdata = stream_get_contents($fileHandle);
fclose($fileHandle);
// Send POST request to server
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
Accept-Language: en-us,en;q=0.5\r\n
Accept-Encoding: gzip, deflate\r\n
Accept-Charset: UTF-8,*\r\n
Keep-Alive: 115\r\n
Cookie: ".$m[1]."\r\n
Connection: keep-alive\r\n
Referer: http://abcdef.com/v2.swf\r\n
Content-Type: application/x-amf\r\n
Content-Length: 50\r\n",
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://abcdef.com/engine/', false, $context);
print_r($result);
结果是空白页面而不是服务器的响应。
I'm trying to reproduce a POST request that was captured from WireShark using PHP. This POST request was sent by a Flash (.swf) object, so it's a little bit complicated in configuring the header.
It does not print out anything in the end, so there must be something wrong with PHP code that I could not see.
Here is what WireShark captured:
POST /engine/ HTTP/1.1\r\n
Host: abcdef.com\r\n
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
Accept-Language: en-us,en;q=0.5\r\n
Accept-Encoding: gzip, deflate\r\n
Accept-Charset: UTF-8,*\r\n
Keep-Alive: 115\r\n
Connection: keep-alive\r\n
Cookie: __utma=77520967.190998754.1302600802.1302605710.1302693085.3; __utmz=77520967.1302600802.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); PHPSESSID=vqtt7v2l5h10nd06fdsuii49e0; __utmc=77520967
Referer: http://abcdef.com/v2.swf\r\n\r\n
Referer: http://abcdef.com/v2.swf\r\n
Content-Type: application/x-amf\r\n
Content-Length: 50\r\n
\r\n
Here is the PHP code with info.txt was made by a HEX editor and all info are correct (i.e. 50 bytes, exact HEX content captured by WireShark)
// Get cookie
$ch = curl_init('http://abcdef.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
preg_match('/^Set-Cookie: (.*?);/m', curl_exec($ch), $m);
// Read x-amf data
$fileHandle = fopen("info.txt", "rb");
$postdata = stream_get_contents($fileHandle);
fclose($fileHandle);
// Send POST request to server
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
Accept-Language: en-us,en;q=0.5\r\n
Accept-Encoding: gzip, deflate\r\n
Accept-Charset: UTF-8,*\r\n
Keep-Alive: 115\r\n
Cookie: ".$m[1]."\r\n
Connection: keep-alive\r\n
Referer: http://abcdef.com/v2.swf\r\n
Content-Type: application/x-amf\r\n
Content-Length: 50\r\n",
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://abcdef.com/engine/', false, $context);
print_r($result);
The result is a blank page instead of response from server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案示例:
Example Solution: