请在我的Java脚本下面找到运行curl
命令的命令,该命令必须获取所有请求标头。
public class Test
{
public static void main(String[] args) throws ClientProtocolException, IOException
{
String url="https://www.url.com/";
String[] command = {"curl", "-v", "--header", "Pragma: x-cache-on,x-cache-remote-on,x-check-cacheable,x-get-cache-key,x-get-extracted-values,x-get-nonces,x-get-ssl-client-session-id,x-get-true-cache-key,x-serial-no,-x-get-request-id", url};
ProcessBuilder process = new ProcessBuilder(command);
Process p;
try
{
p = process.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
System.out.println("reading: "+reader.readLine()); //Not getting any output
StringBuilder builder = new StringBuilder();
String line = null;
while ( (line = reader.readLine()) != null)
{
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
String result = builder.toString();
System.out.print("output: "+result); //No output
}
catch (Exception e)
{
System.out.print("error"); //No exception
e.printStackTrace();
}
}
}
当我在命令提示符下运行上面提到的curl命令时,我能够得到正确的输出。
请帮我在Java脚本中获取相同的输出。