Thomas_L Posted March 24, 2021 Share Posted March 24, 2021 (edited) I have a working API that I can get a json web token from in curl on my server, jquery ajax, postman, anything id like but php cURL.. I need help. I'm sure I'm over looking something easy. $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'http://xxxxx/xxxxx/xxxx/auth/login', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'{ "checked":"", "username":"xxxxxxxx", "password":"xxxxxxxx" }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); echo $response; Here is my Ajax code that works: <script> var settings = { "url": "xxxxxxx/xxxxxxx/xxxxxxxxx", "crossDomain": "true", "method": "POST", "timeout": 0, "headers": { "Content-Type": "application/json" }, "data": JSON.stringify({ "checked": "", "username": "xxxxxxxx", "password": "xxxxxxxx" }), }; $.ajax(settings).done(function (response) { console.log(response); }); </script> Im lost. I have checked that cURL is enabled on my server. I have tested pulling webpages with cURL with out post data just fine. Edited March 24, 2021 by Thomas_L remove url Quote Link to comment https://forums.phpfreaks.com/topic/312374-php-curl-post-help/ Share on other sites More sharing options...
Barand Posted March 24, 2021 Share Posted March 24, 2021 If your cUrl postfields are hard-coded with the username and password, why are you sending them from the ajax call in the POST data? Quote Link to comment https://forums.phpfreaks.com/topic/312374-php-curl-post-help/#findComment-1585357 Share on other sites More sharing options...
Thomas_L Posted March 24, 2021 Author Share Posted March 24, 2021 (edited) @Barand I am not doing both. This was just to show you all what I did as well in AJAX. My cURL code is posted first the ajax 2nd. Edited March 24, 2021 by Thomas_L Quote Link to comment https://forums.phpfreaks.com/topic/312374-php-curl-post-help/#findComment-1585358 Share on other sites More sharing options...
NotionCommotion Posted March 25, 2021 Share Posted March 25, 2021 Hi Thomas, No direct answer, but have you tried logging/echoing/whatever at the server what it is receiving regarding url, body, headers, etc? Don't know the answer to your issues, but guarantee that if you are getting different results, you are sending a different request. Quote Link to comment https://forums.phpfreaks.com/topic/312374-php-curl-post-help/#findComment-1585360 Share on other sites More sharing options...
Thomas_L Posted March 25, 2021 Author Share Posted March 25, 2021 Thanks @NotionCommotion Ill have to get with our dev team that manages the backend to the APIs for further server side testing. Was hoping to find the easy i'm over looking. Quote Link to comment https://forums.phpfreaks.com/topic/312374-php-curl-post-help/#findComment-1585361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.