Welcome Guest, Not a member yet? Register   Sign In
curlrequest post - returning 500 server error
#1

Hi team,

I'm just getting into CI4, and attempting to move some things over from CI3. 

In using the curlrequest method, I can GET data just fine, but I'm having trouble with POST. It's a very simple method, below: 

Code:
public function postData($api) {
        $postdata = ['form_params' => $this->myarray()];
        //Logging
        $log = TRUE;
        if ($log === TRUE) {
            log_message('critical', "Posted::" . print_r($postdata, TRUE));
        }

        $client = \Config\Services::curlrequest();
        $response = $client->request('POST', 'https://myapisite.com/' . $api, $postdata);
        $body = $response->getBody();

        return json_decode($body, TRUE);
    }

Unfortunately the logging doesn't really tell me very much about what's going on:


Quote:CRITICAL - 2020-04-03 10:26:21 --> Posted::Array
(
    [form_params] => Array
        (
            [name] => My User
            [state] => Oregon
            [country] => USA
            [lang-pref] => en_US
        )

)

CRITICAL - 2020-04-03 10:26:21 --> 22 : The requested URL returned error: 500 Internal Server Error
#0 D:\xampp\htdocs\CodeIgniter4\system\HTTP\CURLRequest.php(823): CodeIgniter\HTTP\Exceptions\HTTPException::forCurlError('22', 'The requested U...')
#1 D:\xampp\htdocs\CodeIgniter4\system\HTTP\CURLRequest.php(449): CodeIgniter\HTTP\CURLRequest->sendRequest(Array)
#2 D:\xampp\htdocs\CodeIgniter4\system\HTTP\CURLRequest.php(158): CodeIgniter\HTTP\CURLRequest->send('POST', 'https://myapis...')
#3 D:\xampp\htdocs\CodeIgniter4\app\Libraries\Supersite.php(109): CodeIgniter\HTTP\CURLRequest->request('POST', 'https://myapis...', Array)
#4 D:\xampp\htdocs\CodeIgniter4\app\Controllers\Test.php(41): App\Libraries\Supersite->postData('api/customers/m...')
#5 D:\xampp\htdocs\CodeIgniter4\system\CodeIgniter.php(910): App\Controllers\Test->changedata()
#6 D:\xampp\htdocs\CodeIgniter4\system\CodeIgniter.php(398): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Test))
#7 D:\xampp\htdocs\CodeIgniter4\system\CodeIgniter.php(306): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#8 D:\xampp\htdocs\CodeIgniter4\public\index.php(45): CodeIgniter\CodeIgniter->run()
#9 {main}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB