note 111911 rejected from httpresponse.getrequestbody by aharvey
| From: | aharvey@php.net | Date: | Thu, 11 Apr 2013 00:05:03 +0000 |
| Subject: | note 111911 rejected from httpresponse.getrequestbody by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194443@lists.php.net to get a copy of this message | ||
Note Submitter: randomMadness
----
//------------------REQUEST SIDE----------------------------------------------------
$url = 'http://localhost/topcoat/module.php';
$request = new HttpRequest($url, HttpRequest::METH_POST);
$postFields = array(
'CARDTYPE' => $cardType // setting up the POST fields with values
);
$request->addPostFields($postFields); //adding the POSt fields with the request
try {
$request->send();
//---------------------------HERE THE REQUEST IS SENT---------------------
//-------------------BELOW: RECEIVED from the HttpResponse-----------------
$respData = $request->getResponseData();
if($respData['body'] == "Whatever") // this is how the actual
body can be accessed as $respData in this case is an associative array
{ //do something }
} catch (HttpException $ex) {
$displayMessage = "Wrong server connection";
}
//-----------END OF REQUEST and END OF COMMUNICATION------------------
//-------------RESPONSE SIDE--------------------------------------------------------------
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if($_POST['CARDTYPE'] == "American Express") // WORKING
{
//$responseHead = "RESPONSE"; -- optional, I do not find it useful, but someone
may
$responseData = "Whatever";
}
}
HttpResponse::setData($responseData); // setting up the data structure
//HttpResponse::setHeader($responseHead); -- optional
HttpResponse::send(); //sending the actual response
//this worked for me
//the following DID NOT WORK for me with HttpResponse
$request = HttpResponse::getRequestBody();
EXAMPLE 1: if($request['POST'] == "American Express") {....;}
EXAMPLE 2: if($request['CARDTYPE'] == "American Express") {....;}
EXAMPLE 3: if($request == "American Express") {....;}
I'm a PHP newbie anyway! Cheers