Click here to Skip to main content
15,886,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a form and wrote the code to process the form data input using php/cURL in order to return the
response body, when i inputed the session code and BVN in the form then clicked on submit instead of
returning the response body as below it returned a different result.
What i want is for the code to return a response body, kindly look into the code and profer a solution.

This is what i want to be returned after supplying the required session code and BVN
Response Body

JavaScript
{
  "Success": true,
  "Errors": [],
  "SearchResult": [
    {
      "Relevance": 100,
      "BVN": "46582409734",
      "RegistryID": "68793545132457697809856",
      "Name": "Gbenga Sulaiman",
      "DOBI": "1970-10-20T00:00:00",
      "Phone": "08098764562",
      "Address": "231, Oba Akran, Allen Avenue\r\nIkeja\\ 035 Lagos",
      "EmailAddress": "gbenga@aol.com",
      "IDs": "",
      "Gender": "Male",
      "CustomerType": "Person",
      "Picture": ""
    }
  ],
  "StatusCode": 200,
  "Message": "BVN '46582409734' matched 1 customer(s)."
}


JavaScript
Not this, that returned instead
array(12) { [0]=> string(31) "HTTP/1.1 405 Method Not Allowed" [1]=> string(23) "Cache-Control: no-cache" 
[2]=> string(16) "Pragma: no-cache" [3]=> string(11) "Allow: POST" [4]=> string(45) "Content-Type: 
application/json; charset=utf-8" [5]=> string(11) "Expires: -1" [6]=> string(26) "Server: 
Microsoft-IIS/10.0" [7]=> string(27) "X-AspNet-Version: 4.0.30319" [8]=> string(21) 
"X-Powered-By: ASP.NET" [9]=> string(35) "Date: Sun, 12 Sep 2021 20:51:20 GMT" [10]=> string(22) 
"Connection: keep-alive" [11]=> string(18) "Content-Length: 72" } {"Success":true,
"Errors":[],"EmailAddress":"Lipalater@gareadvancefinancial.com","Authenticated":true,
"SessionCode":"149613","AgentID":"737838731263300529",
"AgentName":"Gare Advance Financial Limited AutoCred Test Agent","SubscriberID":"737838737107069765",
"SubscriberName":"Gare Advance Financial Limited","StatusCode":200,"Message":""}



My Code

PHP
<?php
    session_start();
    if (empty($_SESSION['login']) || $_SESSION['login'] == false) {
        header('Location: /index2.php');
        exit;
    }
    
    $msg = empty($_SESSION['msg']) ? false : $_SESSION['msg'];
    
    if ($msg) {
       // Display the message in the dashboard
       echo $msg . "</br>" ;

       $data = array(
        'EmailAddress' => 'Lipalater@gareadvancefinancial.com',
        'Password' => 'Durosimi4Eti2021#',
        'SubscriberID' => '737838737107069765'
        );
    
        $url = "https://api2.creditregistry.com/nigeria/AutoCred/v7.Test/api/Agents/Login";

        $options = array(
        'http' => array(
            'method'  => 'POST',
            'content' => json_encode( $data ),
            'header'=>  "Content-Type: application/json\r\n" .
                        "Accept: application/json\r\n"
            )
        );

        $context  = stream_context_create( $options );
        $result = file_get_contents( $url, false, $context );
        $response = json_decode( $result, true );

        echo $result;
    }

    

    if (isset($_POST['submitMyBVN']) ) 
    { 
        //Wrap this code with the button click
        $data = array(
            'post_request_name_for_mybvn' => $_POST["myBVN"],
            'post_request_name_for_mysessioncode' => $_POST["mySessionCode"],
        );
    
        $url = "https://api2.creditregistry.com/nigeria/AutoCred/v7.Test/api/Customers/FindByBVN";
    
        //$nextPage = "dashboard.php";
    
        $options = array(
        'http' => array(
            'method'  => 'POST',
            'content' => json_encode( $data ),
            'header'=>  "Content-Type: application/json\r\n" .
                        "Accept: application/json\r\n"
            )
        );
    
        $context  = stream_context_create( $options );
        //$result = file_get_contents( $url, false, $context );
        file_get_contents($url, false, stream_context_create(['http' => ['ignore_errors' => true]]));
        var_dump($http_response_header);
        $response = json_decode( $result, true );
    
        //echo $result; to see the result remove comment and add comment to header('Location: '.$nextPage);
        echo $result;
    
        
    }




?>

HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <h3> Welcome to dashboard Method 2  </h3>
    <form action="" method="POST">
        <label>Enter BVN:</label><br />
        <input type="num" name="myBVN" placeholder="Enter BVN" required/>
        <br /><br />
        <label>Enter Session Code:</label><br />
        <input type="num" name="mySessionCode" placeholder="Enter Session Code" required/>

        <br /><br />
        <button type="submit" name="submitMyBVN">Submit</button>
    </form> 
</body>
</html>


What I have tried:

I have tried the following solutions
https://stackoverflow.com/questions/47794910/submit-form-using-curl-in-php
https://stackoverflow.com/questions/61947983/how-to-submit-custom-post-form-via-curl-php-in-wordpress
https://html.form.guide/php-form/php-form-submit/
Posted
Comments
Peter_in_2780 13-Sep-21 21:13pm    
Look at the first item in the array returned:
[0]=> string(31) "HTTP/1.1 405 Method Not Allowed"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900