2014-04-28 2 views
0

html 페이지를 구문 분석하고 싶습니다. 그러나 나는 서버에서 인증 할 때만이 html 페이지를 읽을 수 있습니다. 하지만 내 현재 코드로, 내가 로그인하고 있지 않다의이 와서 여기에 내 현재 코드입니다.WP8에서 CookieContainer 사용

// This functions start when I click a button 
    private void BtLog_Click(object sender, RoutedEventArgs e) 
    { 
     string url = "https://subcard.subway.co.uk/de_cardholder/servlet/SPLoginServlet"; 

     StringBuilder body = new StringBuilder(); 
     body.Append("language=" + "de"); 
     body.Append("&user=" + tbUser.text); 
     body.Append("&password=" + pbPassword.Password); 
     body.Append("&transIdentType=" + "1"); 
     body.Append("&programID=" + "6"); 

     bool isNetwork = NetworkInterface.GetIsNetworkAvailable(); 
     if (!isNetwork) 
     { 
     } 
     else 
     { 
      try 
      { 
       WebClient webClient = new WebClient(); 
       webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded"; // Your Application Header Content-Type 
       webClient.Encoding = Encoding.UTF8; 
       webClient.UploadStringAsync(new Uri(url), "POST", body.ToString(), null); 

       WebClient client = new WebClient(); 
       client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted); 
       client.DownloadStringAsync(new Uri("https://subcard.subway.co.uk/de_cardholder/JSP/SPSummary.jsp")); 
      } 
      catch 
      { 
       MessageBox.Show("Error"); 
      } 
     } 
    } 

    void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
    { 
     MessageBox.Show(e.Result.ToString()); 
     // If the I am logged in and got the string I want to parse it, but first the other thing have to work 
    } 

은 내가 cookiecontainer와 함께 일해야 생각했지만, 이것이 어떻게 작동하는지 모르겠어요. 내 문제에 대한 조언이나 해결책을 가져 주셔서 감사합니다 !!

+0

가능한 복제본 [WebClient에서 쿠키를 어떻게 가져올 수 있습니까?] (http://stackoverflow.com/questions/2825377/how-can-i-get-the-webclient-to-use-cookies) – bdimag

+0

그게 작동 할 수 있지만 WP8에 대한 GetWebRequest 사용할 수 없습니다 : ( – user3493797

답변

0

내 이해에 따르면. CookieContainer는 웹 서버의 세션 또는 인증 정보와 아무 관련이 없습니다.

호출중인 API/웹 서비스에 대한 제어 권한이있는 경우 토큰 정보를 반환 해보십시오. 다음 번에 장치를 인증하라는 http 요청과 함께 토큰을 보냅니다.

+0

내 경험에 의하면, UploadValues ​​기술적으로 올바른 방법으로 양식/POST 로그인을 사용하여 사이트에 로그인 할 수 있습니다 .WebClient를 사용하여 실제로 원하는 경우 로그인했는지, 쿠키를 사용해야하는지, 그리고 WebClient 클래스를 확장하여 재사용 및 재사용 할 수 있는지를 확인해야합니다. – bdimag

관련 문제