Advertisement
Guest User

HMTL Login

a guest
Oct 11th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.61 KB | None | 0 0
  1. Form1.IWClient ist statisch angelegt, damit ich -so wars gedacht- von überall auf diese eingeloggte Verbindung zurückgreifen kann.
  2. internal static ImprovedWebClient IWClient = new ImprovedWebClient();
  3. ...
  4.  
  5. internal class Downloader
  6. { ...
  7. internal Image DownloadCaptcha() //Lädt das aktuelle Captcha als Bild ins Programm und speichert informationen dazu im WebClient ab.
  8.                                 //Allerdings bin ich überfragt, wie/welche ich mitgeben muss
  9.         {
  10.             //string itemsLine = Form1.IWClient.DownloadString("https://pr0gramm.com/api/user/captcha?bust");
  11.             List<string> ItemsList = new List<string>(Form1.IWClient.DownloadString("https://pr0gramm.com/api/user/captcha?bust").Replace("{", "").Replace("}", "").Replace("\"", "").Replace("\\", "").Split(','));
  12.             Form1.IWClient.token = ItemsList[0].Split(':')[1];
  13.             Form1.IWClient.ts = ItemsList[3].Split(':')[1];
  14.             Form1.IWClient.cache = ItemsList[4].Split(':')[1];
  15.             Form1.IWClient.rt = ItemsList[5].Split(':')[1];
  16.             Form1.IWClient.qc = ItemsList[6].Split(':')[1];
  17.             Form1.IWClient.__cfduid = Form1.IWClient.ResponseCookies["__cfduid"].Value;
  18.  
  19.             byte[] imageBytes = Convert.FromBase64String(ItemsList[2]);
  20.             using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
  21.             {
  22.                 Image image = Image.FromStream(ms, true);
  23.                 return image;
  24.             }
  25.         }
  26.  
  27.  
  28.  internal void DoLogin(string username, string password, string captcha)
  29.         {
  30.             //hier hängts, da kommt keine erfolgreiche Antwort zurück. Was muss ich noch machen, damit tmptest kein "403 - keine Berechtigung" wegen nicht-eingeloggt ist??
  31.             Form1.IWClient.UploadValues("https://pr0gramm.com/api/user/login", new NameValueCollection() { { "name", username }, { "password", password }, { "captcha", captcha } });
  32.             string response = Form1.IWClient.DownloadString("https://pr0gramm.com/api/user/login");
  33.             string tmptest = Form1.IWClient.DownloadString("https://pr0gramm.com/api/user/info");
  34.         }
  35. }
  36.  
  37.  
  38. internal class improvedWebClient:WebClient
  39. { //erweiterung des Webclients, damit Cookies gespeichert werden können. Hab ich so aus dem MS-Forum übernommen; Allerdings keine Ahnung, wie ich die Cookeis richitg weiterverwenden kann/muss
  40. internal ImprovedWebClient()
  41.         {
  42.             CookieContainer = new CookieContainer();
  43.             ResponseCookies = new CookieCollection();
  44.         }
  45.  
  46.         internal CookieContainer CookieContainer
  47.         {
  48.             get; private set;
  49.         }
  50.         internal CookieCollection ResponseCookies
  51.         {
  52.             get; set;
  53.         }
  54.        
  55.         //Diese 5 Werte sind beim Aufruf des Captchas verfügbar. Werden diese gebraucht??
  56.         internal string ts = ""; //bsp "1570780258"
  57.         internal string token = ""; //bsp "e5a900ebccda7d9be75f586673be593a"
  58.         //Captcha zu diesem Token zeigt  "czg1y" als base64 String
  59.         internal string cache = ""; //bsp "null"
  60.         internal string rt = ""; //bsp "16"
  61.         internal string qc = ""; //bsp "0"
  62.         //Diese beiden Werte sind beim Login in der Api zu finden(siehe unten)
  63.         internal string nonce = "";
  64.         internal string id = "";
  65.         //Diese beiden werte sind im Firefox Debugger in den Cookies zu finden
  66.         internal string me = ""; //bsp "me=%7B%7D"
  67.         internal string pp = ""; //bsp "pp=24ec2f001ab122e8120fab2d1a905e74"
  68.         internal string __cfduid = ""; //bsp "__cfduid=db62115a5a99057caae0bd5f0cf9b5df91569494646"
  69.  
  70.  
  71.  
  72.         protected override WebRequest GetWebRequest(Uri address)
  73.         {
  74.             var request = (HttpWebRequest)base.GetWebRequest(address);
  75.             request.CookieContainer = CookieContainer;
  76.             return request;
  77.         }
  78.  
  79.         protected override WebResponse GetWebResponse(WebRequest request)
  80.         {
  81.             var response = (HttpWebResponse)base.GetWebResponse(request);
  82.             ResponseCookies = response.Cookies;
  83.             return response;
  84.         }
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91. //Teil der alten API Dokumentation; allerdings bin ich überfragt, was genau ich damit machen kann/muss...
  92. //      {
  93. //          "name": "user",
  94. //          "item": [
  95. //              {
  96. //                  "name": "Login",
  97. //                  "event": [
  98. //                      {
  99. //                          "listen": "test",
  100. //                          "script": {
  101. //                              "id": "6a45ef56-d4cd-4028-9a6c-64a90b37c55b",
  102. //                              "exec": [
  103. //                                  "let me = JSON.parse(pm.cookies.get(\"me\"));",
  104. //                                  "pm.environment.set(\"nonce\", me.id.substring(0,16));",
  105. //                                  "pm.environment.set(\"id\", me.id);"
  106. //                              ],
  107. //                              "type": "text/javascript"
  108. //                          }
  109. //                      }
  110. //                  ],
  111. //                  "request": {
  112. //                      "method": "POST",
  113. //                      "header": [
  114. //                          {
  115. //                              "key": "Content-Type",
  116. //                              "name": "Content-Type",
  117. //                              "value": "application/x-www-form-urlencoded",
  118. //                              "type": "text"
  119. //                          }
  120. //                      ],
  121. //                      "body": {
  122. //                          "mode": "urlencoded",
  123. //                          "urlencoded": [
  124. //                              {
  125. //                                  "key": "name",
  126. //                                  "value": "{{name}}",
  127. //                                  "description": "Nutzername",
  128. //                                  "type": "text"
  129. //                              },
  130. //                              {
  131. //                                  "key": "password",
  132. //                                  "value": "{{password}}",
  133. //                                  "description": "Passwort",
  134. //                                  "type": "text"
  135. //                              }
  136. //                          ]
  137. //                      },
  138. //                      "url": {
  139. //                          "raw": "https://pr0gramm.com/api/user/login",
  140. //                          "protocol": "https",
  141. //                          "host": [
  142. //                              "pr0gramm",
  143. //                              "com"
  144. //                          ],
  145. //                          "path": [
  146. //                              "api",
  147. //                              "user",
  148. //                              "login"
  149. //                          ]
  150. //                      }
  151. //                  },
  152. //                  "response": []
  153. //              },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement