From 7c0e22258a5365ec416f4b3a699fb9e2a3cfc009 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Sat, 10 Dec 2016 11:17:21 +0100 Subject: [PATCH] Cardigann: Add support for form login with enctype=multipart/form-data --- src/Jackett/Indexers/CardigannIndexer.cs | 30 ++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Jackett/Indexers/CardigannIndexer.cs b/src/Jackett/Indexers/CardigannIndexer.cs index 7383bdf29..38cce50fd 100644 --- a/src/Jackett/Indexers/CardigannIndexer.cs +++ b/src/Jackett/Indexers/CardigannIndexer.cs @@ -438,8 +438,34 @@ namespace Jackett.Indexers pairs["captchaSelection"] = captchaSelection; pairs["submitme"] = "X"; } - - var loginResult = await RequestLoginAndFollowRedirect(submitUrl.ToString(), pairs, configData.CookieHeader.Value, true, null, SiteLink, true); + + WebClientStringResult loginResult = null; + var enctype = form.GetAttribute("enctype"); + if (enctype == "multipart/form-data") + { + var headers = new Dictionary(); + var boundary = "---------------------------" + (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString().Replace(".", ""); + var bodyParts = new List(); + + foreach (var pair in pairs) + { + var part = "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"" + pair.Key + "\"\r\n" + + "\r\n" + + pair.Value; + bodyParts.Add(part); + } + + bodyParts.Add("--" + boundary + "--"); + + headers.Add("Content-Type", "multipart/form-data; boundary=" + boundary); + var body = string.Join("\r\n", bodyParts); + logger.Error(body); + loginResult = await PostDataWithCookies(submitUrl.ToString(), pairs, configData.CookieHeader.Value, SiteLink, headers, body); + } else { + loginResult = await RequestLoginAndFollowRedirect(submitUrl.ToString(), pairs, configData.CookieHeader.Value, true, null, SiteLink, true); + } + configData.CookieHeader.Value = loginResult.Cookies; checkForLoginError(loginResult);