2 // System.Net.WebRequest
\r
5 // Lawrence Pit (loz@cable.a2000.nl)
\r
9 using System.Collections;
\r
10 using System.Collections.Specialized;
\r
11 using System.Configuration;
\r
13 using System.Runtime.Serialization;
\r
15 namespace System.Net
\r
18 public abstract class WebRequest : MarshalByRefObject, ISerializable
\r
20 static HybridDictionary prefixes = new HybridDictionary ();
\r
24 static WebRequest ()
\r
26 ConfigurationSettings.GetConfig ("system.net/webRequestModules");
\r
29 protected WebRequest () { }
\r
31 protected WebRequest (SerializationInfo serializationInfo, StreamingContext streamingContext)
\r
33 throw new NotSupportedException ();
\r
38 public virtual string ConnectionGroupName {
\r
39 get { throw new NotSupportedException (); }
\r
40 set { throw new NotSupportedException (); }
\r
43 public virtual long ContentLength {
\r
44 get { throw new NotSupportedException (); }
\r
45 set { throw new NotSupportedException (); }
\r
48 public virtual string ContentType {
\r
49 get { throw new NotSupportedException (); }
\r
50 set { throw new NotSupportedException (); }
\r
53 public virtual ICredentials Credentials {
\r
54 get { throw new NotSupportedException (); }
\r
55 set { throw new NotSupportedException (); }
\r
58 public virtual WebHeaderCollection Headers {
\r
59 get { throw new NotSupportedException (); }
\r
60 set { throw new NotSupportedException (); }
\r
63 public virtual string Method {
\r
64 get { throw new NotSupportedException (); }
\r
65 set { throw new NotSupportedException (); }
\r
68 public virtual bool PreAuthenticate {
\r
69 get { throw new NotSupportedException (); }
\r
70 set { throw new NotSupportedException (); }
\r
73 public virtual IWebProxy Proxy {
\r
74 get { throw new NotSupportedException (); }
\r
75 set { throw new NotSupportedException (); }
\r
78 public virtual Uri RequestUri {
\r
79 get { throw new NotSupportedException (); }
\r
82 public virtual int Timeout {
\r
83 get { throw new NotSupportedException (); }
\r
84 set { throw new NotSupportedException (); }
\r
89 public virtual void Abort()
\r
91 throw new NotSupportedException ();
\r
94 public virtual IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)
\r
96 throw new NotSupportedException ();
\r
99 public virtual IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
\r
101 throw new NotSupportedException ();
\r
104 public static WebRequest Create (string requestUriString)
\r
106 if (requestUriString == null)
\r
107 throw new ArgumentNullException ("requestUriString");
\r
108 return Create (new Uri (requestUriString));
\r
111 public static WebRequest Create (Uri requestUri)
\r
113 if (requestUri == null)
\r
114 throw new ArgumentNullException ("requestUri");
\r
115 return GetCreator (requestUri.AbsoluteUri).Create (requestUri);
\r
118 public static WebRequest CreateDefault (Uri requestUri)
\r
120 if (requestUri == null)
\r
121 throw new ArgumentNullException ("requestUri");
\r
122 return GetCreator (requestUri.Scheme).Create (requestUri);
\r
125 public virtual Stream EndGetRequestStream (IAsyncResult asyncResult)
\r
127 throw new NotSupportedException ();
\r
130 public virtual WebResponse EndGetResponse (IAsyncResult asyncResult)
\r
132 throw new NotSupportedException ();
\r
135 public virtual Stream GetRequestStream()
\r
137 throw new NotSupportedException ();
\r
140 public virtual WebResponse GetResponse()
\r
142 throw new NotSupportedException ();
\r
145 void ISerializable.GetObjectData (SerializationInfo serializationInfo,
\r
146 StreamingContext streamingContext)
\r
148 throw new NotSupportedException ();
\r
151 public static bool RegisterPrefix (string prefix, IWebRequestCreate creator)
\r
153 if (prefix == null)
\r
154 throw new ArgumentNullException("prefix");
\r
155 if (creator == null)
\r
156 throw new ArgumentNullException("creator");
\r
158 lock (prefixes.SyncRoot) {
\r
159 string lowerCasePrefix = prefix.ToLower ();
\r
160 if (prefixes.Contains (lowerCasePrefix))
\r
162 prefixes.Add (lowerCasePrefix, creator);
\r
167 private static IWebRequestCreate GetCreator (string prefix)
\r
169 int longestPrefix = -1;
\r
170 IWebRequestCreate creator = null;
\r
172 prefix = prefix.ToLower ();
\r
174 IDictionaryEnumerator e = prefixes.GetEnumerator ();
\r
175 while (e.MoveNext ()) {
\r
176 string key = e.Key as string;
\r
178 if (key.Length <= longestPrefix)
\r
181 if (!prefix.StartsWith (key))
\r
184 longestPrefix = key.Length;
\r
185 creator = (IWebRequestCreate) e.Value;
\r
188 if (creator == null)
\r
189 throw new NotSupportedException (prefix);
\r
194 internal static void ClearPrefixes ()
\r
199 internal static void RemovePrefix (string prefix)
\r
201 prefixes.Remove (prefix);
\r
204 internal static void AddPrefix (string prefix, string typeName)
\r
206 Type type = Type.GetType (typeName);
\r
208 throw new ConfigurationException (String.Format ("Type {0} not found", typeName));
\r
210 object o = Activator.CreateInstance (type, true);
\r
211 prefixes [prefix] = o;
\r