Welcome Guest, Not a member yet? Register   Sign In
CURL problem
#1

Hello!

I ger null CSP with CURL request

Curl standart code (work good for me):

PHP Code:
                $ch curl_init();
        
curl_setopt($chCURLOPT_URL'http://127.0.0.1:8545');
        
curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
curl_setopt($chCURLOPT_POST1);
        
curl_setopt($chCURLOPT_HTTPHEADER, array(
            
'Content-Type: application/json'
        
));
        
curl_setopt($chCURLOPT_POSTFIELDSjson_encode($payload));
        
$result curl_exec($ch);
        
curl_close($ch); 

Equivalent CI:

PHP Code:
$result $client->request('POST''http://127.0.0.1:8545/', [
            
'data' => json_encode($payload),
            
'headers' => [
                
'User-Agent' => 'curl/1.0',
                
'Content-Type' => 'application/json',
            ],
        ]); 

1 method work good.
CI method response:

Code:
"CSP": null

How do I go next? any ideas
Reply
#2

(This post was last modified: 02-22-2020, 10:02 AM by dave friend.)

I think the problem is that the cURL class does not have a "data" option. It should be "body".
Give this a try.

PHP Code:
$result $client->request('POST''http://127.0.0.1:8545/', [
    'body'    => json_encode($payload),  // note: 'body', not 'data'
    'headers' => [
        'User-Agent'  => 'curl/1.0',
        'Content-Type' => 'application/json',
    ],
]); 


If that solves your problem you might want to try using the 'json' option. It adds the Content-Type = 'application/json' header and calls json_encode for you.

PHP Code:
$result $client->request('POST''http://127.0.0.1:8545/', [
    'json'    => $payload,  
    
'headers' => [
        'User-Agent'  => 'curl/1.0'
    ],
]); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB