Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JSP中执行cURL命令_Jsp_Servlets - Fatal编程技术网

在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

如何在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=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 ();