3
我正在写一个测试porgram在java中测试我的连接到django restfull api(准确地说是djangorestframework)。 其中一个选项是用卷曲测试api的。 运行从shell curl命令它工作正常: 例如为:从processbuilder执行curl与java
curl --show-error --request GET --header 'Accept: application/json' --user "user:pwd" http://127.0.0.1:8000/api/v1/
这将返回很好的API根URL和帮助文件JSON格式。
现在,当我尝试调用从Java一样,采用的ProcessBuilder,我得到这样的回答:
{"detail": "You do not have permission to access this resource. You may need to login or otherwise authenticate the request."}
我使用的Java代码:
ProcessBuilder p=new ProcessBuilder("curl","--show-error", "--request","GET",
"--header","'Accept: application/json'", "--user","\"" + userName + ":" + password + "\"", getApiRootUrlString());
final Process shell = p.start();
因为我也赶上错误流通过:
InputStream errorStream= shell.getErrorStream();
InputStream shellIn = shell.getInputStream();
我知道他开始curl命令,因为在其中一个选项中的错误显示t他卷曲帮助文本。
我不确定调用它有什么区别,很确定它是相同的命令。
顺便说一下,“getApiRootUrlString()返回正确的网址:http://127.0.0.1:8000/api/v1/
ahhhh愚蠢的我,当然!感谢名单!我只是测试它,而且......(我在测试之前已经知道你是对的) – 2012-07-11 22:41:39