In my case, a specific HTTP request will work in curl inside Git Bash on Windows. However, when starting in Java using HttpClient and HttpGet (org.apache.http.client.methods.HttpGet) I would get a Connection Reset error.
If I tried to use exec to run the command directly, for some reason this will not work.
As a workaround, this code will write the command in a batch file, then run the batch file and put the output in the command.txt file.
Here is the command that should be in the command.bat file (I changed the endpoint and password):
"C:\Users\scottizu\AppData\Local\Programs\Git\bin\sh.exe" --login -i -c "curl 'https://my.server.com/validate/user/scottizu' -H 'Password: MY_PASSWORD' > command.txt"
Here is the code (note that the command has special characters):
import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; public class CURL_Runner { public static void main (String[] args) throws Exception { String command = "\"C:\\Users\\scottizu\\AppData\\Local\\Programs\\Git\\bin\\sh.exe\" --login -i -c \"curl 'https://my.server.com/validate/user/scottizu' -H 'Password: MY_PASSWORD' > command.txt\""; createAndExecuteBatchFile(command); } public static void createAndExecuteBatchFile(String command) throws Exception {
Scott Izu Jul 07 '17 at 21:38 2017-07-07 21:38
source share