Jump to content

Error returned in curl response


johnman
 Share

Recommended Posts

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

Link to comment
Share on other sites

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;
        }

 

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.