-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebClientEx.cs
40 lines (34 loc) · 1.01 KB
/
WebClientEx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Net;
namespace MusicBeePlugin
{
class WebClientEx : WebClient
{
public string PreviousReferer { get; private set; }
public CookieContainer CookieContainer { get; set; }
public WebClientEx()
: base()
{
CookieContainer = new CookieContainer();
}
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address);
if (request is HttpWebRequest req)
{
if (PreviousReferer != null)
{
req.Referer = PreviousReferer;
}
req.CookieContainer = CookieContainer;
}
return request;
}
protected override WebResponse GetWebResponse(WebRequest request)
{
var response = base.GetWebResponse(request);
PreviousReferer = response.ResponseUri.AbsoluteUri;
return response;
}
}
}