2012-04-07 3 views
0

.aspx 사이트가 HttpComponents를 사용하여 게시 요청을 통해 세션 ID 쿠키를 생성하지 않는 문제가 있습니다.asp.net 및 Java HttpComponents 게시 요청에 문제가 있습니다.

웹 사이트는 학교의 온라인 일정보기에 대한 로그인입니다. https://www.lectio.dk/lectio/22/login.aspx 는 또한 나는 페이스트 빈에 HTML을 게시 : http://pastebin.com/nMhxfgjL

(Brugernavn는 사용자 이름과 adgangskode는 password입니다)

내가 m $ 콘텐츠 $의 사용자 이름 2와 m의 $ 콘텐츠 $ 암호 2

로 입력 필드의 이름을 확인

내 코드는 다음과 같습니다

DefaultHttpClient httpclient = new DefaultHttpClient(); 

    HttpGet httpget = new HttpGet("https://www.lectio.dk/lectio/22/login.aspx"); 

    HttpResponse response = httpclient.execute(httpget); 
    HttpEntity entity = response.getEntity(); 

    System.out.println("Login form get: " + response.getStatusLine()); 
    if (entity != null) { 
     entity.consumeContent(); 
    } 

    System.out.println("Initial set of cookies:"); 
    List<Cookie> cookies = httpclient.getCookieStore().getCookies(); 
    if (cookies.isEmpty()) { 
     System.out.println("None"); 
    } else { 
     for (int i = 0; i < cookies.size(); i++) { 
      System.out.println("- " + cookies.get(i).toString()); 
     } 
    } 

    HttpPost httpost = new HttpPost("https://www.lectio.dk/lectio/22/login.aspx"); 

    List<NameValuePair> nvps = new ArrayList<NameValuePair>(); 
    nvps.add(new BasicNameValuePair("m$Content$username2", "blabla")); //set your own username 
    nvps.add(new BasicNameValuePair("m$Content$password2", "blabla")); //set your own password 

    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); 

    response = httpclient.execute(httpost); 
    entity = response.getEntity(); 

    System.out.println("Login form get: " + response.getStatusLine()); 
    if (entity != null) { 
     entity.consumeContent(); 
    } 

    System.out.println("Post logon cookies:"); 
    cookies = httpclient.getCookieStore().getCookies(); 
    if (cookies.isEmpty()) { 
     System.out.println("None"); 
    } else { 
     for (int i = 0; i < cookies.size(); i++) { 
      System.out.println("- " + cookies.get(i).toString()); 
     } 
    } 

분명한 이유를 들어 내 사용자 이름과 암호를 포함하지 않았다. HTTP/쿠키 1.1 200 OK

초기 설정 :

내가 그것을 실행에서 얻을 출력은

로그인 폼 GET이다 버전 : 0] [이름 : lecmobile] [값 : 0] [도메인 : www.lectio.dk] [경로 : /] [만료일 : 12 월 31 일 월요일 00:00:00 CET 2029]

[버전 : 0] [이름 : lectiogsc] [값 : 831859d3-370c-a582-340d-0377177bfcae] [도메인 : www.lectio.dk] [경로 : /] [만료 : 토 1월 1일 중부 유럽 표준시 00시 59분 59초 10000]

로그인 폼 GET : HTTP/1.1 200 OK

후 로그온 쿠키 :

[버전 : 0] [이름 : lecmobile] [값 : 0] [도메인 : www.lectio.dk] [경로 : /] [만료일 : 12 월 31 일 월요일 00:00:00 CET 2029]

[버전 : 0] [이름 : lectiogsc] 값 : 831859d3-370c-a582-340d-0377177bfcae] 도메인 : www.lectio.dk] 경로 : /[유효 : 토 일월 01 중부 유럽 표준시 00시 59분 59초 10000]

0

중요 한 쿠키는 "ASP.NET_SessionId"입니다. 분명히 당신은 로그인 할 때까지 값을 가지고 있지 않을 것입니다.

또한, 성공적으로 로그인 할 때 리디렉션되므로 HTTP 응답이 200이 아닐 것이라고 생각할 수 있습니다.

도움이 되겠습니까 :)

감사합니다. 마이크.

답변

0

세션 쿠키를 가져 오지 않으면 서버 구성 문제 일 수 있습니다.

+0

두려워하지 않습니다. 게시물 요청과 관련된 문제입니다. 수동으로 로그인하면 세션 쿠키가 생성됩니다. –

+0

참고 용 : 세션 쿠키는 로그인 할 필요가 없습니다. 세션 관리가 활성화 된 경우 첫 번째 요청의 응답에 세션 쿠키가있을 수 있습니다. –

+0

브라우저에서 테스트하여 볼 수 있듯이이 경우입니다. :) –

관련 문제