note 111911 added to httpresponse.getrequestbody

From: Date: Wed, 10 Apr 2013 20:17:21 +0000
Subject: note 111911 added to httpresponse.getrequestbody
Groups: php.notes 
Request: Send a blank email to php-notes+get-194435@lists.php.net to get a copy of this message
//------------------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 ---- Server IP: 69.147.83.199 Probable Submitter: 176.61.113.58 ---- Manual Page -- http://php.net/manual/en/httpresponse.getrequestbody.php Edit -- https://master.php.net/note/edit/111911 Del: integrated -- https://master.php.net/note/delete/111911/integrated Del: useless -- https://master.php.net/note/delete/111911/useless Del: bad code -- https://master.php.net/note/delete/111911/bad+code Del: spam -- https://master.php.net/note/delete/111911/spam Del: non-english -- https://master.php.net/note/delete/111911/non-english Del: in docs -- https://master.php.net/note/delete/111911/in+docs Del: other reasons-- https://master.php.net/note/delete/111911 Reject -- https://master.php.net/note/reject/111911 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194435) next »