【发布时间】:2014-09-01 17:27:19
【问题描述】:
我有一个网站,我想向其发布数据。问题是在使用 cakephp httpsocket 功能时,设置自定义端口(例如 8080)将导致端口位于 url 的末尾(而不是主机名的末尾)。查看示例代码:
$notificationUrl = 'www.example.com/LotsController/sendWork';
$request = array(
'method' => 'POST',
'uri' => array(
'scheme' => 'http',
'host' => $notificationUrl,
'port' => 8080,
// 'user' => null,
// 'pass' => null,
// 'path' => null,
// 'query' => null,
// 'fragment' => null
),
// 'auth' => array(
// 'method' => 'Basic',
// 'user' => null,
// 'pass' => null
// ),
// 'version' => '1.1',
'body' => $jsonWithEncryptedData,
// 'line' => null,
// 'header' => array(
// 'Connection' => 'close',
// 'User-Agent' => 'CakePHP'
// ),
// 'raw' => null,
// 'redirect' => false,
// 'cookies' => array()
);
$HttpSocket = new HttpSocket( );
$HTTPPostResults = $HttpSocket->post( $notificationUrl, $jsonWithEncryptedData , $request );
返回的响应 html 代码(状态 404)显示 httpsocket 尝试连接的 url cakephp 是: http://www.example.com/LotsController/sendWork:8080(在浏览器中不起作用)
不应该是: http://www.example.com:8080/LotsController/sendWork(在浏览器中工作)
为什么 cakephp 将端口号放在 url 的末尾?
我的设置: Ubuntu 14 Cakephp 2.5.3
【问题讨论】: