在JSP中执行cURL命令
如何在JSP中执行以下cURL命令在JSP中执行cURL命令,jsp,servlets,Jsp,Servlets,如何在JSP中执行以下cURL命令 $ curl -d lang=fr -d badge=0 http://www.redissever.com/subscriber/J8lHY4X1XkU 如果你用一些代码解释,这会很有帮助。谢谢你可以使用Runtime.getRuntime().exec()从JSP脚本执行任何命令 <% Process p=Runtime.getRuntime().exec("..."); p.waitFor(); BufferedReader reader=n
$ curl -d lang=fr -d badge=0 http://www.redissever.com/subscriber/J8lHY4X1XkU
如果你用一些代码解释,这会很有帮助。谢谢你可以使用
Runtime.getRuntime().exec()
从JSP脚本执行任何命令
<%
Process p=Runtime.getRuntime().exec("...");
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
out.println(line);
line=reader.readLine();
}
%>
对于POST请求,您需要以下内容:
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
wr.writeBytes ("lang=fr&badge=0");
wr.flush ();
wr.close ();
你为什么要这么做?用Java做。我尝试了Runtime.getRuntime().exec(),但它显示的是一个空白页面
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
wr.writeBytes ("lang=fr&badge=0");
wr.flush ();
wr.close ();