| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- //
- // System.Net.WebRequest
- //
- // Authors:
- // Lawrence Pit ([email protected])
- //
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Collections;
- using System.Collections.Specialized;
- using System.Configuration;
- using System.IO;
- using System.Runtime.Serialization;
- namespace System.Net
- {
- [Serializable]
- public abstract class WebRequest : MarshalByRefObject, ISerializable
- {
- static HybridDictionary prefixes = new HybridDictionary ();
-
- // Constructors
-
- static WebRequest ()
- {
- ConfigurationSettings.GetConfig ("system.net/webRequestModules");
- }
-
- protected WebRequest () { }
-
- protected WebRequest (SerializationInfo serializationInfo, StreamingContext streamingContext)
- {
- throw new NotSupportedException ();
- }
-
- // Properties
-
- public virtual string ConnectionGroupName {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
-
- public virtual long ContentLength {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
-
- public virtual string ContentType {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
-
- public virtual ICredentials Credentials {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
-
- public virtual WebHeaderCollection Headers {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
-
- public virtual string Method {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
-
- public virtual bool PreAuthenticate {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
-
- public virtual IWebProxy Proxy {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
-
- public virtual Uri RequestUri {
- get { throw new NotSupportedException (); }
- }
-
- public virtual int Timeout {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
-
- // Methods
-
- public virtual void Abort()
- {
- throw new NotSupportedException ();
- }
-
- public virtual IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)
- {
- throw new NotSupportedException ();
- }
-
- public virtual IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
- {
- throw new NotSupportedException ();
- }
- public static WebRequest Create (string requestUriString)
- {
- if (requestUriString == null)
- throw new ArgumentNullException ("requestUriString");
- return Create (new Uri (requestUriString));
- }
-
- public static WebRequest Create (Uri requestUri)
- {
- if (requestUri == null)
- throw new ArgumentNullException ("requestUri");
- return GetCreator (requestUri.AbsoluteUri).Create (requestUri);
- }
-
- public static WebRequest CreateDefault (Uri requestUri)
- {
- if (requestUri == null)
- throw new ArgumentNullException ("requestUri");
- return GetCreator (requestUri.Scheme).Create (requestUri);
- }
- public virtual Stream EndGetRequestStream (IAsyncResult asyncResult)
- {
- throw new NotSupportedException ();
- }
-
- public virtual WebResponse EndGetResponse (IAsyncResult asyncResult)
- {
- throw new NotSupportedException ();
- }
-
- public virtual Stream GetRequestStream()
- {
- throw new NotSupportedException ();
- }
-
- public virtual WebResponse GetResponse()
- {
- throw new NotSupportedException ();
- }
-
- void ISerializable.GetObjectData (SerializationInfo serializationInfo,
- StreamingContext streamingContext)
- {
- throw new NotSupportedException ();
- }
- public static bool RegisterPrefix (string prefix, IWebRequestCreate creator)
- {
- if (prefix == null)
- throw new ArgumentNullException("prefix");
- if (creator == null)
- throw new ArgumentNullException("creator");
-
- lock (prefixes.SyncRoot) {
- string lowerCasePrefix = prefix.ToLower ();
- if (prefixes.Contains (lowerCasePrefix))
- return false;
- prefixes.Add (lowerCasePrefix, creator);
- }
- return true;
- }
-
- private static IWebRequestCreate GetCreator (string prefix)
- {
- int longestPrefix = -1;
- IWebRequestCreate creator = null;
- prefix = prefix.ToLower ();
- IDictionaryEnumerator e = prefixes.GetEnumerator ();
- while (e.MoveNext ()) {
- string key = e.Key as string;
- if (key.Length <= longestPrefix)
- continue;
-
- if (!prefix.StartsWith (key))
- continue;
-
- longestPrefix = key.Length;
- creator = (IWebRequestCreate) e.Value;
- }
-
- if (creator == null)
- throw new NotSupportedException (prefix);
-
- return creator;
- }
- internal static void ClearPrefixes ()
- {
- prefixes.Clear ();
- }
- internal static void RemovePrefix (string prefix)
- {
- prefixes.Remove (prefix);
- }
- internal static void AddPrefix (string prefix, string typeName)
- {
- Type type = Type.GetType (typeName);
- if (type == null)
- throw new ConfigurationException (String.Format ("Type {0} not found", typeName));
- object o = Activator.CreateInstance (type, true);
- prefixes [prefix] = o;
- }
- }
- }
|