I am executing below command using cURL in java. This gives me error - right after a white space after Bearer
.
2019-07-25 08:04:09,297 INFO [com.pc.boxapi.BoxApi:198] - curl: (6) Couldn't resolve host 'Ddu9DLiWt2YRWxtsoAxjL0BMMbt9FvOk"'
curlCommand = "curl https://upload.box.com/api/2.0/files/content -H \"Authorization:Bearer Ddu9DLiWt2YRWxtsoAxjL0BMMbt9FvOk\" -X POST -F attributes='{\"name\":\"text.txt\",\"parent\":{\"id\":\"69430965158\"}}' -F [email protected]\"";
Process process = Runtime.getRuntime().exec(curlCommand);
LOG.info("process {} ", process.getOutputStream().toString());
if I use a forward slash between Bearer
and Ddu9DLiWt2YRWxtsoAxjL0BMMbt9FvOk
I get another error -
INFO [com.pc.boxapi.BoxApi:198] - curl: (26) failed creating formpost data
Server is Linux
The man
page of curl
says that error code 26 stands for Read error. Various reading problems.
.
If you just print the command you're trying to execute, you get this :
curl https://upload.box.com/api/2.0/files/content -H "Authorization:Bearer Ddu9DLiWt2YRWxtsoAxjL0BMMbt9FvOk" -X POST -F attributes='{"name":"text.txt","parent":{"id":"69430965158"}}' -F [email protected]"
A read problem is probably related to -F [email protected]"
. Notice the extra "
at the end of the filename. I'm pretty sure your problem is here. Remove it and make sure file.txt
exists.
By the way, if you need to make HTTP requests in Java, you should use a library like Apache HttpClient.
Avoid executing a system command at all costs, it's a security issue waiting to append!