【问题标题】:Cakephp : httpsocket and custom port causing wrong urlCakephp:httpsocket和自定义端口导致错误的url
【发布时间】: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

【问题讨论】:

    标签: cakephp port


    【解决方案1】:

    host 是您要连接的 url 的基域,即

    www.example.com
    

    不是网址

    www.example.com/LotsController/sendWork
    

    您应该在路径中而不是在主机中包含其他信息

    【讨论】:

      猜你喜欢
      • 2012-07-21
      • 2014-08-23
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多