Welcome Guest, Not a member yet? Register   Sign In
CURL Request Class - urlencode
#1

(This post was last modified: 08-17-2024, 09:58 AM by 68thorby68.)

Hi,
I working with a 3rd Party API and need to configure the URL as per the 3rd party spec.
PHP Code:
$my_row $client->get('/THIRDPARTY/?filter__Company%20Name__equal=my%20company%20(sports%20department) 

However, CURL Request Class encodes the url to:
Code:
GET /THIRDPARTY/?filter__Company_Name__equal=my+company+%28sports+department%29
Is there a way to instruct the CURL Request Class not to encode the url? 
I can't see anything obvious in the documentation and the only setting I can find in Config->CURLRequest is
PHP Code:
public $shareOptions true
Any help is appreciated
Reply
#2

(08-17-2024, 09:58 AM)68thorby68 Wrote: Is there a way to instruct the CURL Request Class not to encode the url? 

No.

Use `query` option to send a request with query string.
https://codeigniter.com/user_guide/libra...html#query
Reply
#3

(08-17-2024, 06:58 PM)kenjis Wrote:
(08-17-2024, 09:58 AM)68thorby68 Wrote: Is there a way to instruct the CURL Request Class not to encode the url? 

No.

Use `query` option to send a request with query string.
https://codeigniter.com/user_guide/libra...html#query


Many thanks kenjis, with logging, my request is now and works perfectly, Thank you
My code new reads:
PHP Code:
$update_row $client->request('GET','/THIRDPARTY/',
 [
    'debug' => WRITEPATH.'curl_logs/curl_log.txt',
    'query' => [
        'user_field_names' => 'true'
        'filter__Company Name__equal' => my company (sports department)

     ], 
    'headers' => [
        'Content-Type' => 'application/json',
        'Authorization' => [mytoken]
    ],
    'json' => [
    
]); 
from the logs, this outputs
Code:
GET /THIRDPARTY/?user_field_names=true&filter__Company+Name__equal=my+company+%28sports+department%29


Just to note, when I use the format
PHP Code:
$update_row $client->get('/THIRDPARTY/?user_field_names=true&filter__Company Name__equal=my company (sports department), 
The CURL Request Class edits the url to
Code:
GET /THIRDPARTY/?user_field_names=true&filter__Company_Name__equal=my+company+%28sports+department%29
The issue being the space between Company and Name in parameter filter__Company Name__equal is being replaced with an underscore rather and plus!!!

Again many thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB