0
상태 기반 http 서버와 상호 작용하는 java를 사용하여 HTTP 클라이언트를 코딩해야합니다. 클라이언트는 Java를 사용하여 원격 서버로 HttpClient 대화 형을 작성하는 방법
- 탐색 할 필요가
이 클라이언트를 구현하기 위해 HttpClient를 사용하려고합니다. 그러나 로그인 양식을 제출 했음에도 불구하고 여전히 제출 양식이 유효하지 않은 것처럼 로그인 양식을 반환합니다. 여기 내 코드는 다음과 같습니다.
HttpClient agent = new DefaultHttpClient();
agent.getParams().setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.RFC_2965);
CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGet httpget = new HttpGet(site);
HttpResponse response = agent.execute(httpget, localContext);
HttpEntity entity = response.getEntity();
entity.getContent().close();
HttpPost post = new HttpPost(site + "/login.aspx");
post.getParams().setParameter("LoginControl1$ctlLoginName", "myusername");
post.getParams().setParameter("LoginControl1$ctlPassword", "mypassword");
response = agent.execute(post, localContext);
entity = response.getEntity();
String s = IO.readContentAsString(entity.getContent());
System.out.println(s);
내가 잘못했는지 아십니까? 아니면 이것을 구현하는 더 좋은 방법이 있습니까?
감사 잘못,하지만 당신은 서버와 원시 HTTP 대화를 잡고 당신이 HttpClient를에 송신/수신하는지 비교하는 tcpdump를/와이어 샤크를 사용하여 생각해야 할 수도 있습니다 무엇 녹색