나는 django의 restfull API (정확하게 djangorestframework)에 대한 연결을 테스트하기 위해 java에 테스트 프로그램을 작성하고 있습니다. 옵션 중 하나는 곱슬 곱슬하게 API를 테스트하는 것입니다. 쉘에서 curl 명령을 실행 그것을 잘 작동합니다 : 예컨대 :processbuilder를 사용하여 Java에서 컬 실행
curl --show-error --request GET --header 'Accept: application/json' --user "user:pwd" http://127.0.0.1:8000/api/v1/
이 JSON 형식으로 멋지게 API를 루트 URL 및 도움말 텍스트를 반환합니다.
{"detail": "You do not have permission to access this resource. You may need to login or otherwise authenticate the request."}
내가 사용하고 자바 코드는 다음과 같습니다 : 나는 ProcessBuilder를을 사용하여 자바에서 같은를 호출 할 때
지금, 나는이 답변을 얻을
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();
옵션 중 하나에서 실수를하면 t 그는 도움말 텍스트를 말린다.
나는 그것을 불러내는 것의 차이점을 확실히 알지 못한다. 확실히 같은 명령이다. 그런데
는 'getApiRootUrlString()는'올바른 URL을 반환 http://127.0.0.1:8000/api/v1/
어리석은 나를 물론! 고맙습니다! 나는 방금 그것을 시험했고, 실제로 .... (나는 당신이 시험하기 전에 이미 알고 있었다) –