Base URL changing by itself

nelolka created this issue on 2021-06-03 · The issue is replied 1 times

Base URL changing automatically if you make a request with slashes in the URL.

<?php
require __DIR__ .'/vendor/autoload.php';

use Curl\Curl;

$curl = new Curl('https://example.com/');

$curl->get('test/aaa');

$curl->get('test/bbb'); //request url must be https://example.com/test/bbb
echo $curl->requestHeaders['request-line'].PHP_EOL; //GET /test/test/bbb HTTP/2

$curl->get('test/ccc'); //request url must be https://example.com/test/ccc
echo $curl->requestHeaders['request-line'].PHP_EOL; //GET /test/test/test/ccc HTTP/2

$curl->get('https://httpbin.org/');
$curl->get('test/ccc'); //request url must be https://example.com/test/ccc
echo $curl->requestHeaders['host'].PHP_EOL; //httpbin.org
zachborboa wrote this answer on 2021-06-07

Hi. Explanations are inline:

$curl = new Curl('https://example.com/');

// Results in https://example.com/test/aaa because "test/aaa" is a relative url.
$curl->get('test/aaa');

// Results in https://example.com/test/test/bbb because "test/bbb" is a relative url.
// Use $curl->get('/test/bbb'); with a leading slash to get https://example.com/test/bbb
$curl->get('test/bbb');

// Results in https://example.com/test/test/test/ccc because "test/ccc" is a relative url.
// Use $curl->get('/test/ccc'); with a leading slash to get https://example.com/test/ccc
$curl->get('test/ccc');

// Results in https://httpbin.org/ because the domain changed.
$curl->get('https://httpbin.org/');

// Results in https://httpbin.org/test/ccc because "test/ccc" is a relative url.
$curl->get('test/ccc');
More Details About Repo
Owner Name php-curl-class
Repo Name php-curl-class
Full Name php-curl-class/php-curl-class
Language PHP
Created Date 2013-08-16
Updated Date 2021-11-21
Star Count 2879
Watcher Count 166
Fork Count 759
Issue Count 2

YOU MAY BE INTERESTED

Issue Title State Comments Created Date Updated Date Closed Date
Icon request: bullet (unicode U+2022: •) open 2 2021-09-08 2021-10-03 -
饼图(pie)label无法设置backgroundColor颜色,也没法设置背景图片 open 1 2019-07-16 2021-11-13 -
Can't build closed 1 2020-12-02 2021-11-07 2020-12-04
Add: Notifications (Inbox) open 0 2021-07-15 2021-11-17 -
App crash after allowing the camera permission open 15 2021-07-04 2021-11-16 -
[BUG] [imageVerify] verifyImages rule type is not enabled in background scan open 1 2021-11-18 2021-11-15 -
Export to markdown closed 3 2021-07-17 2021-11-15 2021-08-20
Planet Python not showing posts closed 1 2017-12-16 2021-11-11 2021-04-12
Required-validation doesn't change upon input closed 1 2021-07-24 2021-11-19 2021-07-25
使用 "图片描述" 后行内图片无法实现行内行为 closed 2 2021-09-13 2021-11-17 2021-09-18