2010-03-03 7 views
7

मैं एक vbulletin मंच में लॉग इन करने की कोशिश कर रहा हूँ। मैं इतनी दूर मिल गया:सी # के साथ एक vbulletin मंच में लॉग इन करने के लिए कैसे?

private string login(string url, string username, string password) 
{ 
string values = "vb_login_username={0}&vb_login_password={1}" 
values += "&securitytoken=guest&cookieuser=checked&do=login"; 

values = string.Format(values, username, password); 
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); 
CookieContainer a = new CookieContainer(); 
req.CookieContainer = a; 

System.Net.ServicePointManager.Expect100Continue = false; // prevents 417 error 

using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)) 
{ writer.Write(values); } 

this.response = (HttpWebResponse)req.GetResponse(); 

StringBuilder output = new StringBuilder(); 

foreach (var cookie in response.Cookies) 
{ 
output.Append(cookie.ToString()); 
output.Append(";"); 
} 


return output.ToString(); 
} 

ऐसा लगता है कि मैं की तरह में लॉग इन कर रहा हूँ, लेकिन जब मैं पेज डाउनलोड, मैं अपने उपयोगकर्ता नाम उस में नहीं मिल सकता है।

क्या आप लोग कुछ भी देखते हैं कि मैं गलत कर रहा हूं?

अग्रिम धन्यवाद!

उत्तर

1

मुझे यकीन नहीं है कि मैं आपका अनुसरण करता हूं या नहीं। वीबीबी के साथ आपका क्या मतलब है?

यदि आप vb.com में थ्रेड पोस्ट करना चाहते हैं, तो मैं आपको बता सकता हूं कि vb.org में vb.org में एक थ्रेड खोला गया है जो 'vb3 प्रोग्रामिंग चर्चा' (मेरे द्वारा पोस्ट नहीं किया गया) में खोला गया है। यह तीसरे पृष्ठ पर होना चाहिए, 'सी #' से शुरू होता है।

यदि आपका मतलब आपकी पोस्ट के साथ कुछ और है, तो क्या आप इसे थोड़ा सा स्पष्ट कर सकते हैं?

+1

उपयोग यह कर सकते हैं आप एक जवाब का जवाब देना चाहते हैं, तो आप एक पोस्ट है कि टिप्पणी के नीचे "टिप्पणी जोड़ने के" लिंक का उपयोग करना चाहिए, बजाय अपनी टिप्पणी का जवाब दें। –

6

आप का उपयोग HTTP अनुरोध इस विधि

public string Login(Uri ActionUrl, string postData) 
     { 

      gRequest = (HttpWebRequest)WebRequest.Create(formActionUrl); 
      gRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 GTBDFff GTB7.0"; 

      gRequest.CookieContainer = new CookieContainer(); 
      gRequest.Method = "POST"; 
      gRequest.Accept = " text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, */*"; 
      gRequest.KeepAlive = true; 
      gRequest.ContentType = @"application/x-www-form-urlencoded"; 


      #region CookieManagement 
      if (this.gCookies != null && this.gCookies.Count > 0) 
      { 

       gRequest.CookieContainer.Add(gCookies); 
      } 


      try 
      { 

       string postdata = string.Format(postData); 
       byte[] postBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(postData); 
       gRequest.ContentLength = postBuffer.Length; 
       Stream postDataStream = gRequest.GetRequestStream(); 
       postDataStream.Write(postBuffer, 0, postBuffer.Length); 
       postDataStream.Close(); 
      } 
      catch (Exception ex) 
      { 
       Console.WriteLine(ex.Message); 

      } 



      try 
      { 
       gResponse = (HttpWebResponse)gRequest.GetResponse(); 
      } 
      catch (Exception ex) 
      { 
       Console.WriteLine(ex); 

      } 



      //check if the status code is http 200 or http ok 

       if (gResponse.StatusCode == HttpStatusCode.OK) 
       { 
        //get all the cookies from the current request and add them to the response object cookies 

        gResponse.Cookies = gRequest.CookieContainer.GetCookies(gRequest.RequestUri); 
        //check if response object has any cookies or not 
        if (gResponse.Cookies.Count > 0) 
        { 
         //check if this is the first request/response, if this is the response of first request gCookies 
         //will be null 
         if (this.gCookies == null) 
         { 
          gCookies = gResponse.Cookies; 
         } 
         else 
         { 
          foreach (Cookie oRespCookie in gResponse.Cookies) 
          { 
           bool bMatch = false; 
           foreach (Cookie oReqCookie in this.gCookies) 
           { 
            if (oReqCookie.Name == oRespCookie.Name) 
            { 
             oReqCookie.Value = oRespCookie.Name; 
             bMatch = true; 
             break; // 
            } 
           } 
           if (!bMatch) 
            this.gCookies.Add(oRespCookie); 
          } 
         } 
        } 
      #endregion 



        StreamReader reader = new StreamReader(gResponse.GetResponseStream()); 
        string responseString = reader.ReadToEnd(); 
        reader.Close(); 
        //Console.Write("Response String:" + responseString); 
        return responseString; 
       } 
       else 
       { 
        return "Error in posting data"; 
       } 

     } 
+0

आप http शीर्षलेख –

+1

पढ़कर पोस्टडेटा प्राप्त कर सकते हैं आप उपयोगकर्ता नाम और पासवर्ड कहां सेट करते हैं? – Yustme

संबंधित मुद्दे