Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Form1.IWClient ist statisch angelegt, damit ich -so wars gedacht- von überall auf diese eingeloggte Verbindung zurückgreifen kann.
- internal static ImprovedWebClient IWClient = new ImprovedWebClient();
- ...
- internal class Downloader
- { ...
- internal Image DownloadCaptcha() //Lädt das aktuelle Captcha als Bild ins Programm und speichert informationen dazu im WebClient ab.
- //Allerdings bin ich überfragt, wie/welche ich mitgeben muss
- {
- //string itemsLine = Form1.IWClient.DownloadString("https://pr0gramm.com/api/user/captcha?bust");
- List<string> ItemsList = new List<string>(Form1.IWClient.DownloadString("https://pr0gramm.com/api/user/captcha?bust").Replace("{", "").Replace("}", "").Replace("\"", "").Replace("\\", "").Split(','));
- Form1.IWClient.token = ItemsList[0].Split(':')[1];
- Form1.IWClient.ts = ItemsList[3].Split(':')[1];
- Form1.IWClient.cache = ItemsList[4].Split(':')[1];
- Form1.IWClient.rt = ItemsList[5].Split(':')[1];
- Form1.IWClient.qc = ItemsList[6].Split(':')[1];
- Form1.IWClient.__cfduid = Form1.IWClient.ResponseCookies["__cfduid"].Value;
- byte[] imageBytes = Convert.FromBase64String(ItemsList[2]);
- using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
- {
- Image image = Image.FromStream(ms, true);
- return image;
- }
- }
- internal void DoLogin(string username, string password, string captcha)
- {
- //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??
- Form1.IWClient.UploadValues("https://pr0gramm.com/api/user/login", new NameValueCollection() { { "name", username }, { "password", password }, { "captcha", captcha } });
- string response = Form1.IWClient.DownloadString("https://pr0gramm.com/api/user/login");
- string tmptest = Form1.IWClient.DownloadString("https://pr0gramm.com/api/user/info");
- }
- }
- internal class improvedWebClient:WebClient
- { //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
- internal ImprovedWebClient()
- {
- CookieContainer = new CookieContainer();
- ResponseCookies = new CookieCollection();
- }
- internal CookieContainer CookieContainer
- {
- get; private set;
- }
- internal CookieCollection ResponseCookies
- {
- get; set;
- }
- //Diese 5 Werte sind beim Aufruf des Captchas verfügbar. Werden diese gebraucht??
- internal string ts = ""; //bsp "1570780258"
- internal string token = ""; //bsp "e5a900ebccda7d9be75f586673be593a"
- //Captcha zu diesem Token zeigt "czg1y" als base64 String
- internal string cache = ""; //bsp "null"
- internal string rt = ""; //bsp "16"
- internal string qc = ""; //bsp "0"
- //Diese beiden Werte sind beim Login in der Api zu finden(siehe unten)
- internal string nonce = "";
- internal string id = "";
- //Diese beiden werte sind im Firefox Debugger in den Cookies zu finden
- internal string me = ""; //bsp "me=%7B%7D"
- internal string pp = ""; //bsp "pp=24ec2f001ab122e8120fab2d1a905e74"
- internal string __cfduid = ""; //bsp "__cfduid=db62115a5a99057caae0bd5f0cf9b5df91569494646"
- protected override WebRequest GetWebRequest(Uri address)
- {
- var request = (HttpWebRequest)base.GetWebRequest(address);
- request.CookieContainer = CookieContainer;
- return request;
- }
- protected override WebResponse GetWebResponse(WebRequest request)
- {
- var response = (HttpWebResponse)base.GetWebResponse(request);
- ResponseCookies = response.Cookies;
- return response;
- }
- }
- //Teil der alten API Dokumentation; allerdings bin ich überfragt, was genau ich damit machen kann/muss...
- // {
- // "name": "user",
- // "item": [
- // {
- // "name": "Login",
- // "event": [
- // {
- // "listen": "test",
- // "script": {
- // "id": "6a45ef56-d4cd-4028-9a6c-64a90b37c55b",
- // "exec": [
- // "let me = JSON.parse(pm.cookies.get(\"me\"));",
- // "pm.environment.set(\"nonce\", me.id.substring(0,16));",
- // "pm.environment.set(\"id\", me.id);"
- // ],
- // "type": "text/javascript"
- // }
- // }
- // ],
- // "request": {
- // "method": "POST",
- // "header": [
- // {
- // "key": "Content-Type",
- // "name": "Content-Type",
- // "value": "application/x-www-form-urlencoded",
- // "type": "text"
- // }
- // ],
- // "body": {
- // "mode": "urlencoded",
- // "urlencoded": [
- // {
- // "key": "name",
- // "value": "{{name}}",
- // "description": "Nutzername",
- // "type": "text"
- // },
- // {
- // "key": "password",
- // "value": "{{password}}",
- // "description": "Passwort",
- // "type": "text"
- // }
- // ]
- // },
- // "url": {
- // "raw": "https://pr0gramm.com/api/user/login",
- // "protocol": "https",
- // "host": [
- // "pr0gramm",
- // "com"
- // ],
- // "path": [
- // "api",
- // "user",
- // "login"
- // ]
- // }
- // },
- // "response": []
- // },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement