Advertisement
Guest User

Untitled

a guest
Aug 25th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. private async static void getsessionToken()
  2.         {
  3.             //logindaten
  4.             string euserver = "virgon";
  5.             string username = "bieg";
  6.             string password = "bug";
  7.  
  8.             //"roh"-sessionstuff
  9.             //was zum f** ist der pattern
  10.             string pattern_authuser_and_token = @"r'.*action="+ @"https://sas.bpsecure.com/Sas/Authentication/Bigpoint\?authUser=(\d+)&token=([a-zA-Z0-9-_]*)'";
  11.             string mainrequest = $"https://{euserver}.bsgo.com/";
  12.  
  13.             //webrequest
  14.             HttpClient client = new HttpClient();
  15.             HttpResponseMessage response = await client.GetAsync(mainrequest);
  16.             HttpContent content = response.Content;
  17.             string mycontent = await content.ReadAsStringAsync();
  18.             foreach (string line in mycontent.Split('\n'))
  19.             {
  20.                 if (line.Contains("token"))
  21.                 {
  22.                    
  23.                     Match matches = Regex.Match(pattern_authuser_and_token, line);
  24.                     Group authUser = matches.Groups[1];
  25.                     Group token = matches.Groups[2];
  26.                    
  27.  
  28.                     using (StreamWriter sw = new StreamWriter(@"mytest.txt", true))
  29.                         sw.WriteLine(line);
  30.  
  31.  
  32.                     var headers = "Content-Type" + "application/x-www-form-urlencoded";
  33.  
  34.                     string url = $"https://sas.bpsecure.com/Sas/Authentication/Bigpoint?authUser={authUser}&token={token}";
  35.  
  36.  
  37.                     List<KeyValuePair<string, string>> queries = new List<KeyValuePair<string, string>>()
  38.                     {
  39.                         new KeyValuePair<string, string>($"username{username}",$"password{password}")
  40.                     };
  41.                                
  42.                     HttpContent loginrequest = new FormUrlEncodedContent(queries);
  43.  
  44.  
  45.                     using(HttpClient client2 = new HttpClient())
  46.                     {
  47.                         using (HttpResponseMessage login = await client2.PostAsync(url, loginrequest))
  48.                         {
  49.                             using(HttpContent content2 = login.Content)
  50.                             {
  51.                                 string mycontent2 = await content2.ReadAsStringAsync();
  52.                                 using (StreamWriter sw = new StreamWriter(@"mytest.txt", true))
  53.                                     sw.WriteLine(mycontent2);
  54.                             }
  55.                         }
  56.                     }
  57.          
  58.                 }
  59.                
  60.             }
  61.  
  62.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement