2016-09-06 6 views
1

아래의 샘플 코드는 http 클라이언트에 있습니다.하지만 같은 코드를 Rest Assured에 쓰고 싶습니다. 나는 우리가뿐만 아니라 안심의 HTTP lib 디렉토리를 사용할 수있어,하지만 난 나머지에 갖고 싶어 나머지는 당신이 코드 아래 사용할 수 있습니다 피보험자를 들어url 인코딩 된 양식 엔티티를 설정하고 params를 나머지 양식 엔티티에 추가하는 방법은 무엇입니까?

HttpPost pst = new HttpPost(baseUrl, "j_spring_security_check")) 
pst.setHeader("Content-Type", "application/x-www-form-urlencoded") 
ArrayList<NameValuePair> postParam = new ArrayList<NameValuePair>() 
postParam .add(new BasicNameValuePair("j_username",username)) 
postParam .add(new BasicNameValuePair("j_password",password)) 
UrlEncodedFormEntity formEntity23 = new UrlEncodedFormEntity(postParam) 
pst.setEntity(formEntity23) 
HttpResponse response = httpclient.execute(pst); 

답변

2

을 안심하시기 바랍니다.

Response response = RestAssured.given().header("Content-Type", "application/x-www-form-urlencoded").formParam("j_username", "uName").formParam("j_password", "pwd").request().post(url); 

응용 프로그램이 양식 URL 인코딩 된 콘텐츠 형식을 사용하기 때문에 위에서 설명한대로 헤더 유형을 설정할 수 있습니다.

희망, 도움이됩니다.