Merge branch 'master' of https://git.hiimray.co.uk/SympatheticFire/hiimray-co-uk-www-posts
This commit is contained in:
commit
abd93908fb
@ -18,35 +18,30 @@ namespace RyzStudio.Net
|
||||
{
|
||||
}
|
||||
|
||||
public HttpWebRequest CreateRequest(string url)
|
||||
{
|
||||
return this.CreateRequest(url, url);
|
||||
}
|
||||
public HttpWebRequest CreateRequest(string requestURL) => this.CreateRequest(requestURL, requestURL);
|
||||
|
||||
public HttpWebRequest CreateRequest(string url, string referrerURL)
|
||||
public HttpWebRequest CreateRequest(string requestURL, string referrerURL)
|
||||
{
|
||||
if (defaultCookierContainer == null)
|
||||
{
|
||||
defaultCookierContainer = new CookieContainer();
|
||||
}
|
||||
|
||||
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(requestURL);
|
||||
webRequest.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
|
||||
webRequest.MaximumAutomaticRedirections = defaultMaxRedirect;
|
||||
webRequest.CookieContainer = defaultCookierContainer;
|
||||
webRequest.UserAgent = defaultUserAgent;
|
||||
webRequest.AllowAutoRedirect = defaultAllowRedirect;
|
||||
webRequest.Timeout = defaultTimeout;
|
||||
webRequest.Referer = referrerURL;
|
||||
|
||||
return webRequest;
|
||||
}
|
||||
|
||||
public int GetResponse(out string sourceCode, string url, string referrerURL = "")
|
||||
{
|
||||
HttpWebRequest webRequest = this.CreateRequest(url, referrerURL);
|
||||
public int GetResponse(out string sourceCode, string requestURL) => this.GetResponse(out sourceCode, this.CreateRequest(requestURL));
|
||||
|
||||
return GetResponse(out sourceCode, webRequest);
|
||||
}
|
||||
public int GetResponse(out string sourceCode, string requestURL, string referrerURL) => this.GetResponse(out sourceCode, this.CreateRequest(requestURL, referrerURL));
|
||||
|
||||
public int GetResponse(out string sourceCode, HttpWebRequest webRequest)
|
||||
{
|
||||
@ -93,18 +88,59 @@ namespace RyzStudio.Net
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static HttpWebRequest AddBasicAuthentication(HttpWebRequest webRequest, string username, string password)
|
||||
{
|
||||
webRequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(string.Concat(username, ":", password)));
|
||||
webRequest.PreAuthenticate = true;
|
||||
public int GetResponse(out HttpWebRequest webRequest, out string sourceCode, string requestURL) => this.GetResponse(out webRequest, out sourceCode, requestURL, requestURL, true);
|
||||
|
||||
return webRequest;
|
||||
public int GetResponse(out HttpWebRequest webRequest, out string sourceCode, string requestURL, bool allowAutoRedirect) => this.GetResponse(out webRequest, out sourceCode, requestURL, requestURL, allowAutoRedirect);
|
||||
|
||||
public int GetResponse(out HttpWebRequest webRequest, out string sourceCode, string requestURL, string referrerURL) => this.GetResponse(out webRequest, out sourceCode, requestURL, referrerURL, true);
|
||||
|
||||
public int GetResponse(out HttpWebRequest webRequest, out string sourceCode, string requestURL, string referrerURL, bool allowAutoRedirect)
|
||||
{
|
||||
webRequest = this.CreateRequest(requestURL, referrerURL);
|
||||
webRequest.AllowAutoRedirect = allowAutoRedirect;
|
||||
|
||||
return this.GetResponse(out sourceCode, webRequest);
|
||||
}
|
||||
|
||||
public int GetHEADResponse(string requestURL) => this.GetHEADResponse(requestURL, requestURL, true);
|
||||
|
||||
public int GetHEADResponse(string requestURL, string referrerURL) => this.GetHEADResponse(requestURL, requestURL, true);
|
||||
|
||||
public int GetHEADResponse(string requestURL, bool allowAutoRedirect) => this.GetHEADResponse(requestURL, requestURL, allowAutoRedirect);
|
||||
|
||||
public int GetHEADResponse(string requestURL, string referrerURL, bool allowAutoRedirect)
|
||||
{
|
||||
HttpWebRequest webRequest = this.CreateRequest(requestURL, referrerURL);
|
||||
webRequest.Method = "HEAD";
|
||||
webRequest.AllowAutoRedirect = allowAutoRedirect;
|
||||
|
||||
string sc;
|
||||
int rc = this.GetResponse(out sc, webRequest);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
public int GetHEADResponse(out HttpWebRequest webRequest, string requestURL) => this.GetHEADResponse(out webRequest, requestURL, requestURL, true);
|
||||
|
||||
public int GetHEADResponse(out HttpWebRequest webRequest, string requestURL, string referrerURL) => this.GetHEADResponse(out webRequest, requestURL, referrerURL, true);
|
||||
|
||||
public int GetHEADResponse(out HttpWebRequest webRequest, string requestURL, bool allowAutoRedirect) => this.GetHEADResponse(out webRequest, requestURL, requestURL, allowAutoRedirect);
|
||||
|
||||
public int GetHEADResponse(out HttpWebRequest webRequest, string requestURL, string referrerURL, bool allowAutoRedirect)
|
||||
{
|
||||
webRequest = this.CreateRequest(requestURL, referrerURL);
|
||||
webRequest.Method = "HEAD";
|
||||
webRequest.AllowAutoRedirect = allowAutoRedirect;
|
||||
|
||||
string sc;
|
||||
int rc = this.GetResponse(out sc, webRequest);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
public int GetPOSTResponse(out string sourceCode, HttpWebRequest webRequest, string postData)
|
||||
{
|
||||
sourceCode = "";
|
||||
sourceCode = string.Empty;
|
||||
int rv = 0;
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(postData);
|
||||
|
||||
@ -164,5 +200,14 @@ namespace RyzStudio.Net
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static HttpWebRequest AddBasicAuthentication(HttpWebRequest webRequest, string username, string password)
|
||||
{
|
||||
webRequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(string.Concat(username, ":", password)));
|
||||
webRequest.PreAuthenticate = true;
|
||||
|
||||
return webRequest;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user