简体   繁体   English

使用Curl捕获通过POST通过Java代理从PHP发送到Java Rest WS的POST发送的输入参数

[英]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. 我一直在开发一个应用程序,其中涉及使用PHP脚本作为客户端和Java Restful WS。

The way the PHP consumes the WS is throuh POST using curl: PHP使用WS的方式是通过curl使用POST:

$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. 对于应用程序的需求,我有一个代理正在侦听我的所有请求,该代理需要接收URL,因为我需要从URL中提取一些元素,例如参数。

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; 当我使用GET时,没有问题,在我的代理中使用Java套接字,我可以从输入流中检索几乎所有数据。 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? 我知道当您使用POST时,不能像get中一样接收数据,但是有什么方法可以像GET中那样提取参数或完整的请求URL?

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. 始终获取URL(标题部分)中的参数,而POST在正文部分包含参数。 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. 我的Java类实际上是问题所在,因为它仅检索标头,因为它在有行时迭代接收到的请求,如果它检测到并为空行,则循环会中断,但是要将标头与主体分开,必须有两个空行他们之间,所以这就是为什么我看不到我的参数。 Hope it helps somebody with the same issue, thank you! 希望它对遇到同样问题的人有所帮助,谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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