Britc
Britc

Reputation: 633

Cakephp : httpsocket and custom port causing wrong url

I have a site which I would like to POST data to. The problem is when using cakephp httpsocket feature, setting a custom port (e.g. 8080) will cause the port to be at the end of the url (instead at the end of the hostname). See sample code :

    $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 );

Returned response html code (status 404) shows that the url cakephp httpsocket is trying to connect to is : http://www.example.com/LotsController/sendWork:8080 (does not work in browser)

Shouldn't it be : http://www.example.com:8080/LotsController/sendWork (works in browser)

Why is cakephp putting the port number at the end of the url ?

My Settings : Ubuntu 14 Cakephp 2.5.3

Upvotes: 0

Views: 370

Answers (1)

Abhishek
Abhishek

Reputation: 805

host is the base domain of the url you want to connect which is

www.example.com

not the url

www.example.com/LotsController/sendWork

you should include other information in path instead of in host

Upvotes: 1

Related Questions