Tag: django rest framework

使用processbuilder从java执行curl

我正在java中编写测试程序来测试我与django中的restfull api的连接(精确地说是djangorestframework)。 其中一个选择是用curl测试api。 从shell运行curl命令它工作正常:例如: curl –show-error –request GET –header ‘Accept: application/json’ –user “user:pwd” http://127.0.0.1:8000/api/v1/ 这将以json格式很好地返回api根URL和helptext。 现在,当我尝试使用ProcessBuilder从java调用相同的内容时,我得到了这样的答案: {“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 […]