mirror of
https://github.com/Jackett/Jackett
synced 2024-12-29 11:17:22 +00:00
parent
77a2264164
commit
f770596354
6 changed files with 36 additions and 10 deletions
|
@ -214,7 +214,7 @@ namespace Jackett.Common.Utils.Clients
|
|||
else if (webRequest.Type == RequestType.POST)
|
||||
{
|
||||
if (webRequest.PostData != null)
|
||||
request.Content = new FormUrlEncodedContent(webRequest.PostData);
|
||||
request.Content = FormUrlEncodedContentWithEncoding(webRequest.PostData, webRequest.Encoding);
|
||||
request.Method = HttpMethod.Post;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -234,7 +234,7 @@ namespace Jackett.Common.Utils.Clients
|
|||
else if (webRequest.Type == RequestType.POST)
|
||||
{
|
||||
if (webRequest.PostData != null)
|
||||
request.Content = new FormUrlEncodedContent(webRequest.PostData);
|
||||
request.Content = FormUrlEncodedContentWithEncoding(webRequest.PostData, webRequest.Encoding);
|
||||
request.Method = HttpMethod.Post;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -230,7 +230,7 @@ namespace Jackett.Common.Utils.Clients
|
|||
else if (webRequest.Type == RequestType.POST)
|
||||
{
|
||||
if (webRequest.PostData != null)
|
||||
request.Content = new FormUrlEncodedContent(webRequest.PostData);
|
||||
request.Content = FormUrlEncodedContentWithEncoding(webRequest.PostData, webRequest.Encoding);
|
||||
request.Method = HttpMethod.Post;
|
||||
}
|
||||
else
|
||||
|
@ -250,7 +250,7 @@ namespace Jackett.Common.Utils.Clients
|
|||
}
|
||||
|
||||
// some cloudflare clients are using a refresh header
|
||||
// Pull it out manually
|
||||
// Pull it out manually
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable && response.Headers.Contains("Refresh"))
|
||||
{
|
||||
var refreshHeaders = response.Headers.GetValues("Refresh");
|
||||
|
|
|
@ -213,7 +213,7 @@ namespace Jackett.Common.Utils.Clients
|
|||
else if (webRequest.Type == RequestType.POST)
|
||||
{
|
||||
if (webRequest.PostData != null)
|
||||
request.Content = new FormUrlEncodedContent(webRequest.PostData);
|
||||
request.Content = FormUrlEncodedContentWithEncoding(webRequest.PostData, webRequest.Encoding);
|
||||
request.Method = HttpMethod.Post;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using AutoMapper;
|
||||
using Jackett.Common.Models.Config;
|
||||
using Jackett.Common.Services.Interfaces;
|
||||
|
@ -184,5 +187,33 @@ namespace Jackett.Common.Utils.Clients
|
|||
{
|
||||
// nothing by default
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does the same as FormUrlEncodedContent but with custom encoding instead of utf-8
|
||||
* https://stackoverflow.com/a/13832544
|
||||
*/
|
||||
protected static ByteArrayContent FormUrlEncodedContentWithEncoding(
|
||||
IEnumerable<KeyValuePair<string, string>> nameValueCollection, Encoding encoding)
|
||||
{
|
||||
// utf-8 / default
|
||||
if (Encoding.UTF8.Equals(encoding) || encoding == null)
|
||||
return new FormUrlEncodedContent(nameValueCollection);
|
||||
|
||||
// other encodings
|
||||
var builder = new StringBuilder();
|
||||
foreach (KeyValuePair<string, string> pair in nameValueCollection)
|
||||
{
|
||||
if (builder.Length > 0)
|
||||
builder.Append('&');
|
||||
builder.Append(HttpUtility.UrlEncode(pair.Key, encoding));
|
||||
builder.Append('=');
|
||||
builder.Append(HttpUtility.UrlEncode(pair.Value, encoding));
|
||||
}
|
||||
// HttpRuleParser.DefaultHttpEncoding == "latin1"
|
||||
var data = Encoding.GetEncoding("latin1").GetBytes(builder.ToString());
|
||||
var content = new ByteArrayContent(data);
|
||||
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
|
||||
return content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,11 +49,6 @@ namespace Jackett.Common.Utils
|
|||
return Encoding.UTF8.GetString(Convert.FromBase64String(str));
|
||||
}
|
||||
|
||||
public static string PostDataFromDict(IEnumerable<KeyValuePair<string, string>> dict)
|
||||
{
|
||||
return new FormUrlEncodedContent(dict).ReadAsStringAsync().Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert an array of bytes to a string of hex digits
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in a new issue