0

I am working in a php environment and want to receive a Java HTTP Request Object. it will be from an external source to the host website.

the object will be in this format:

 POST /fail?installation=XXXXXX&msgType=authResult HTTP/1.0
 Content-Type: application/x-www-form-urlencoded;charset=UTF-8
 Host: www.worldpay.com
 Content-Length: 973
 User-Agent: WJHRO/1.0 (worldPay Java HTTP Request Object)

 region=new+format+region&authAmountString=%26%23163%3B10.00&_SP.charEnc=UTF8&desc=&tel=&address1=new+format+address1)

i understand from java that i can access the java request object like this;

protected void doGet(
    HttpServletRequest request,
    HttpServletResponse response)
      throws ServletException, IOException {

    String param1 = request.getParameter("param1");
        String param2 = request.getParameter("param2");

}

the issue for me is that i work in php and need to convert the string params into a PHP format/$varables.

i cannot find any online material that can assist me with this and would really appreciate some advice on how to convert it

ragol
  • 527
  • 3
  • 11
Paul Kendal
  • 559
  • 9
  • 24

2 Answers2

0

As you are using HTTP protocol, you don't care what client and server are written in. If you use PHP for backend, you simply need to research what PHP uses to wrap incoming HTTP request (it has nothing to do with your Java).

PHP retrieves POST data in $_POST superglobal variable and query string in $_GET:

$msgType = $_GET['authResult'];
$installation = $_GET['installation'];

From your dump it appears that all that Java magic simply concatenates, URL encodes and puts data to POST body:

$contents = file_get_contents('php://input'); // read request contents
$data = explode('&', $contents);
foreach($data as &$entry) {
     $entry = explode('=', $entry);
     $entry[1] = urldecode($entry[1]);
}
unset($entry);

This should yield following structure:

$data = [
    ['region', 'new format region'],
    ...
];

You can change output format into whatever you prefer.

Im0rtality
  • 3,463
  • 3
  • 31
  • 41
  • hi imortality. thank so much for help. quick question.what did you put inside the file_get_contents() function. should it not be $_POST. i am a bit confused why you put the 'php://input' – Paul Kendal Oct 10 '14 at 09:25
  • i am also a bit confused about teh ($data as &$entry). i have not seen the & before a variable. is there any reason why u used it? – Paul Kendal Oct 10 '14 at 09:26
  • @PaulKendal RE: `php://input` see here: http://stackoverflow.com/a/2731431/421752; RE: `&` - http://stackoverflow.com/a/10121508/421752 – Im0rtality Oct 10 '14 at 09:33
0

This is a standard HTTP POST request. "worldPay Java HTTP Request Object" only means, that it is getting sent by a Java based service. So you won't see anything Java related in your PHP application. Use standard PHP functions to access request data. For POST requests it is $_POST array.

ragol
  • 527
  • 3
  • 11