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
80 set { throw new NotSupportedException (); }
\r
83 public virtual int Timeout {
\r
84 get { throw new NotSupportedException (); }
\r
85 set { throw new NotSupportedException (); }
\r
90 public virtual void Abort()
\r
92 throw new NotSupportedException ();
\r
95 public virtual IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)
\r
97 throw new NotSupportedException ();
\r
100 public virtual IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
\r
102 throw new NotSupportedException ();
\r
105 public static WebRequest Create (string requestUriString)
\r
107 if (requestUriString == null)
\r
108 throw new ArgumentNullException ("requestUriString");
\r
109 return Create (new Uri (requestUriString));
\r
112 public static WebRequest Create (Uri requestUri)
\r
114 if (requestUri == null)
\r
115 throw new ArgumentNullException ("requestUri");
\r
116 return GetCreator (requestUri.AbsoluteUri).Create (requestUri);
\r
119 public static WebRequest CreateDefault (Uri requestUri)
\r
121 if (requestUri == null)
\r
122 throw new ArgumentNullException ("requestUri");
\r
123 return GetCreator (requestUri.Scheme).Create (requestUri);
\r
126 public virtual Stream EndGetRequestStream (IAsyncResult asyncResult)
\r
128 throw new NotSupportedException ();
\r
131 public virtual WebResponse EndGetResponse (IAsyncResult asyncResult)
\r
133 throw new NotSupportedException ();
\r
136 public virtual Stream GetRequestStream()
\r
138 throw new NotSupportedException ();
\r
141 public virtual WebResponse GetResponse()
\r
143 throw new NotSupportedException ();
\r
146 void ISerializable.GetObjectData (SerializationInfo serializationInfo,
\r
147 StreamingContext streamingContext)
\r
149 throw new NotSupportedException ();
\r
152 public static bool RegisterPrefix (string prefix, IWebRequestCreate creator)
\r
154 if (prefix == null)
\r
155 throw new ArgumentNullException("prefix");
\r
156 if (creator == null)
\r
157 throw new ArgumentNullException("creator");
\r
159 lock (prefixes.SyncRoot) {
\r
160 if (prefixes.Contains (prefix))
\r
162 prefixes.Add (prefix.ToLower (), 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);
\r
211 prefixes [prefix] = o;
\r