johnman Posted September 17, 2021 Share Posted September 17, 2021 Good day I tried getting a json response using the below written code but instead it returned the following error message {"Message":"The request entity's media type 'multipart/form-data' is not supported for this resource."} see the code below $mydata = array( 'number1' => $_POST["customerNUM1"], 'number2' => $_POST["sessionNUM1"], ); $headers = array( 'Content-Type' => 'application/json' ); $ch = curl_init($url); // curl_setopt($ch,CURLOPT_COOKIEJAR, $this->cookie_jar); // curl_setopt($ch,CURLOPT_COOKIESESSION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, False); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, False); curl_setopt($ch, CURLOPT_ENCODING, ""); curl_setopt($ch,CURLOPT_MAXREDIRS,0); curl_setopt($ch,CURLOPT_TIMEOUT,30); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $mydata); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $err = curl_error($ch); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } Kindly help Quote Link to comment https://forums.phpfreaks.com/topic/313762-error-returned-in-curl-response/ Share on other sites More sharing options...
johnman Posted September 17, 2021 Author Share Posted September 17, 2021 I edited the above code because the API endpoint is not included, it has been included in the below code $mydata = array( 'number1' => $_POST["customerNUM1"], 'number2' => $_POST["sessionNUM1"], ); $headers = array( 'Content-Type' => 'application/json' ); $url = "https://api2.creditregistry.com/nigeria/AutoCred/v7.Test/api/Customers/FindByBVN2"; $ch = curl_init($url); // curl_setopt($ch,CURLOPT_COOKIEJAR, $this->cookie_jar); // curl_setopt($ch,CURLOPT_COOKIESESSION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, False); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, False); curl_setopt($ch, CURLOPT_ENCODING, ""); curl_setopt($ch,CURLOPT_MAXREDIRS,0); curl_setopt($ch,CURLOPT_TIMEOUT,30); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $mydata); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $err = curl_error($ch); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } Quote Link to comment https://forums.phpfreaks.com/topic/313762-error-returned-in-curl-response/#findComment-1590033 Share on other sites More sharing options...
requinix Posted September 17, 2021 Share Posted September 17, 2021 Setting POSTFIELDS to an array means cURL will encode your data in the "multipart" format. Apparently FindByBVN2 does not like that. If you're supposed to send JSON data then you have to send JSON data. Quote Link to comment https://forums.phpfreaks.com/topic/313762-error-returned-in-curl-response/#findComment-1590051 Share on other sites More sharing options...
johnman Posted September 18, 2021 Author Share Posted September 18, 2021 @requinix thanks you for your reply i will rewrite the code Quote Link to comment https://forums.phpfreaks.com/topic/313762-error-returned-in-curl-response/#findComment-1590076 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.