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


How to get names of parameters from POST request?

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

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

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

附言。我可以访问 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 执行此操作的正确方法。

您是否尝试过在搜索表单上查看源以获取 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
}

虽然这当然是你可以在 PHP 中使用 curl 做的事情,但你应该考虑抓取政府网站以收集和重用其数据的可能后果。

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

您想知道第三方搜索引擎返回的参数。因此,您将使用 curl 将 POST 到有问题的 SE。然后解析返回的页面并提取所需的信息。

编辑:好的,所以你是一个Java人。如果你更习惯使用 shell,请阅读 PHP 的"exec"命令的一些示例。您可能还想查看类似的"系统"和"直通"。