Dirty Bird Design
Dirty Bird Design

Reputation: 5553

How to set up testing back end for PHP cURL

I don't have much experience here, so pls bear with me. I am good with cURL and sending data to API's - right now I want to set up a testing environment as the API isn't ready, but I know what he responses will be.

I will be sending some data to the API via cURL - no issue there. The main variable is called $src and it is a simple POST value. I want to set up a script on another server and echo back some messaging based on $src value. On the remote script, that will mimic the API I'm getting returned messages like "Resource id #4" or "Resource id #5" I realize that is a generic message. Here is what I am trying to do

cURL scripting

foreach($fields as $key=>$value) { 
    $fields_string .= $key.'='.$value.'&'; 
}
$fields_string = rtrim($fields_string,'& ');
$urlFX = 'http://myserver.com/NTLM/testresponse.php';
$ch = curl_init($urlFX);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo($ch);

Test script to mimic API Response:

<?php
    $src = $_GET['src'];
    if($src == "nt-fx-data-test") {
        echo('foo');
    } else {
        echo('bar');
    }
?>

How can I set up a script that will mimic the API's responses based on the $src var value?

Upvotes: 0

Views: 551

Answers (1)

Christian Lescuyer
Christian Lescuyer

Reputation: 19263

Try to hit

http://goelette.net/NTLM/testresponse.php

With params:

  • src=nt-fx-data-test
  • src=xp
  • dst=nt-fx-data-test

Code:

<?php
foreach($_REQUEST as $param => $value) {
    if ($param == 'src' and $value == 'nt-fx-data-test') {
        echo 'foo';
    } else if ($param == 'src' and $value != 'nt-fx-data-test') {
        echo 'bar';
    } else {
        echo "unknown $param";
    }
}

Upvotes: 2

Related Questions