-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRMWebClient.cs
More file actions
58 lines (48 loc) · 1.99 KB
/
RMWebClient.cs
File metadata and controls
58 lines (48 loc) · 1.99 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
RMLib: Nonvisual support classes used by multiple R&M Software programs
Copyright (C) Rick Parrish, R&M Software
This file is part of RMLib.
RMLib is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
RMLib is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with RMLib. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
namespace RandM.RMLib
{
public class RMWebClient : WebClient
{
private CookieContainer _CookieContainer = new CookieContainer();
public string ContentType { get; set; }
public int Timeout { get; set; }
public string UserAgent { get; set; }
public RMWebClient() : base()
{
ContentType = "";
Timeout = 0;
UserAgent = "";
}
protected override WebRequest GetWebRequest(Uri url)
{
WebRequest Request = base.GetWebRequest(url);
if (Request is HttpWebRequest)
{
(Request as HttpWebRequest).CookieContainer = _CookieContainer; // Enable the client to receive/respond with cookies
(Request as HttpWebRequest).Proxy = null; // Disable auto-detect, which can really slow things down
if (!string.IsNullOrEmpty(UserAgent)) (Request as HttpWebRequest).UserAgent = UserAgent;
}
if (!string.IsNullOrEmpty(ContentType)) Request.ContentType = ContentType;
if (Timeout > 0) Request.Timeout = Timeout;
return Request;
}
}
}