如何从POST请求中获取参数名称?

时间:2012-04-29 14:58:35

标签: php web http-post

有搜索服务(PHP)通过POST发送搜索查询。我想在我的应用程序中使用该搜索引擎。 PHP服务没有公共API。

有没有办法输入搜索查询并获取POST请求以查看参数名称?我稍后会使用从我的应用程序发送POST请求并捕获POST响应。

这是一个官方搜索引擎,政府官员没有回复我的请求,告诉我参数的名称。这不是非法的,应用程序是免费的,只是我不能再等他们,因为他们会回复我。

PS。我可以访问Ubuntu shell及其管理工具。

修改

这是搜索表单在网页源中的显示方式(通过浏览器查看)

<form action="search.php" method="POST">
   <input type="text" name="search" size=20><br>
   SZ<input type="checkbox" checked name="sz">
   NZ<input type="checkbox" checked name="nz">
   <input type="submit" name="search_term" value="search" >
</form>

编辑2

不要编辑帖子,因为一个人建议我通过linux命令curl这样做的正确方法。

2 个答案:

答案 0 :(得分:1)

您是否尝试在搜索表单上查看来源以获取POST参数?即输入框的名称

修改 以tizag网站上的php形式为例

<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form action="process.php" method="post"> 
<select name="item"> 
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
Quantity: <input name="quantity" type="text" /> 
<input type="submit" />
</form>
</body></html>

参数是输入名称,即质量和项目

Java代码(将其用于appengine)

HttpURLConnection connection = null;
String line = null;
BufferedReader rd = null;
String urlParameters = "search=search&submit=Submit";
serverAddress = new URL("http://www.search.com/search.php");
// set up out communications stuff
connection = null;
connection = (HttpURLConnection) serverAddress.openConnection();
// connection.setRequestMethod("GET");
connection.setRequestMethod("POST");
connection.setRequestProperty("Referer", "");
connection.setRequestProperty("User-Agent", ""); 
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
connection.connect();
if (connection.getResponseCode() == 404) {
    throw new ErrorException();
}
ArrayList<String> ud = new ArrayList<String>();
rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = rd.readLine()) != null) {
    ud.add(line); // add response to arraylist
}

答案 1 :(得分:0)

虽然这肯定是你可以用curl in PHP做的事情,但你应该考虑刮取政府网站收集和重复使用数据的可能后果。

当然,我不知道您将如何使用数据,数据的重要性,请求的频率或您是否将使用代理。所以可能没有什么可担心的。

您想知道第三方搜索引擎返回的参数。因此,您可以使用curl对相关SE进行POST。然后解析返回的页面并提取您所追踪的信息。

编辑:好的,所以你是一个Java人。如果您更习惯使用shell,请阅读PHP的“exec”命令的一些示例。还有类似的“system”和“passthru”您可能需要查看。