简体   繁体   中英

Catch the input parameter sent through POST from PHP to Java Rest WS through Java Proxy using Curl

I've been developing an application which involves the use of a PHP script as a client and a Java Restful WS.

The way the PHP consumes the WS is throuh POST using curl:

$url = "http://192.168.3.41:8013/module.ModuleSearch/getResults/jsonp"; 

$xmlParam = 'xmlQuery='.$rawXml;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);      
curl_setopt($ch, CURLOPT_POSTFIELDS,$xmlParam);
$info = curl_exec ($ch);
curl_close ($ch);
echo $info;

For the requirements of the application, I have a proxy which is listening to all my requests, this proxy needs to receive the URL because I need to extract some of the elements from the URL, like the parameter.

When I use a GET, there's no problem, using a Java socket in my proxy I can retrieve almost all the data from the input stream; for instance:

|DETECTED|-===========> GET /module.ModuleSearch/getResults/jsonp?idFolder=idPub1&callback=__gwt_jsonp__.P0.onSuccess&failureCallback=__gwt_jsonp__.P0.onFailure HTTP/1.1
|DETECTED|-===========> Host: 192.168.3.41:8013
|DETECTED|-===========> Connection: keep-alive
|DETECTED|-===========> User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Ubuntu Chromium/23.0.1271.97 Chrome/23.0.1271.97 Safari/537.11
|DETECTED|-===========> Accept: */*
|DETECTED|-===========> Referer: http://dev.test.server/php/scriptTest/phpTest.php?idFolder=idPub1/back5&uid=xx&portalIp=192.168.3.41&port=8013
|DETECTED|-===========> Accept-Encoding: gzip,deflate,sdch
|DETECTED|-===========> Accept-Language: es-419,es;q=0.8
|DETECTED|-===========> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
|DETECTED|-===========> 

But in the case of post I just retrieve:

2013-06-03 07:52:19,012 [myid:] - DEBUG [Thread-2:FirstLineScanner@55] - -|DETECTED|-===========> POST /module.ModuleSearch/getResults/jsonp HTTP/1.1
2013-06-03 07:52:19,311 [myid:] - DEBUG [Thread-2:FirstLineScanner@55] - -|DETECTED|-===========> Host: 192.168.3.41:8013
2013-06-03 07:52:19,502 [myid:] - DEBUG [Thread-2:FirstLineScanner@55] - -|DETECTED|-===========> Accept: */*
2013-06-03 07:52:20,125 [myid:] - DEBUG [Thread-2:FirstLineScanner@55] - -|DETECTED|-===========> Content-Length: 31
2013-06-03 07:52:20,404 [myid:] - DEBUG [Thread-2:FirstLineScanner@55] - -|DETECTED|-===========> Content-Type: application/x-www-form-urlencoded
2013-06-03 07:52:21,011 [myid:] - DEBUG [Thread-2:FirstLineScanner@55] - -|DETECTED|-===========> 

I know when you use POST, data cannot be received as in get, but is there any way to extract the parameters or the full request URL as in GET?

Please if somebody could help me I will really appreciate it. Thank you very much in advance.

I solved the issue, it was easy. Get always retrieve parameters in URL (Header parts), while POST has parameters in the body part. My class of Java was actually the problem, since it was retrieving only headers, since it iterates the request recived while it has lines, if it detects and empty line, the loop breaks, but to separate header from body, two blank lines must be between them, so that's why I could have not seen my parameters. Hope it helps somebody with the same issue, thank you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM