2 // System.Net.WebRequest
\r
5 // Lawrence Pit (loz@cable.a2000.nl)
\r
9 using System.Collections;
\r
10 using System.Collections.Specialized;
\r
12 using System.Runtime.Serialization;
\r
14 namespace System.Net
\r
17 public abstract class WebRequest : MarshalByRefObject, ISerializable
\r
19 private static HybridDictionary prefixes;
\r
21 static WebRequest () {
\r
22 prefixes = new HybridDictionary (3, true);
\r
23 RegisterPrefix ("file", new FileWebRequestCreator ());
\r
24 RegisterPrefix ("http", new HttpWebRequestCreator ());
\r
25 RegisterPrefix ("https", new HttpWebRequestCreator ());
\r
28 internal class HttpWebRequestCreator : IWebRequestCreate
\r
30 internal HttpWebRequestCreator () { }
\r
32 public WebRequest Create (Uri uri)
\r
34 return new HttpWebRequest (uri);
\r
38 internal class FileWebRequestCreator : IWebRequestCreate
\r
40 internal FileWebRequestCreator () { }
\r
42 public WebRequest Create (Uri uri)
\r
44 return new FileWebRequest (uri);
\r
51 protected WebRequest () { }
\r
53 protected WebRequest (SerializationInfo serializationInfo, StreamingContext streamingContext)
\r
55 throw new NotSupportedException ();
\r
60 public virtual string ConnectionGroupName {
\r
61 get { throw new NotSupportedException (); }
\r
62 set { throw new NotSupportedException (); }
\r
65 public virtual long ContentLength {
\r
66 get { throw new NotSupportedException (); }
\r
67 set { throw new NotSupportedException (); }
\r
70 public virtual string ContentType {
\r
71 get { throw new NotSupportedException (); }
\r
72 set { throw new NotSupportedException (); }
\r
75 public virtual ICredentials Credentials {
\r
76 get { throw new NotSupportedException (); }
\r
77 set { throw new NotSupportedException (); }
\r
80 public virtual WebHeaderCollection Headers {
\r
81 get { throw new NotSupportedException (); }
\r
82 set { throw new NotSupportedException (); }
\r
85 public virtual string Method {
\r
86 get { throw new NotSupportedException (); }
\r
87 set { throw new NotSupportedException (); }
\r
90 public virtual bool PreAuthenticate {
\r
91 get { throw new NotSupportedException (); }
\r
92 set { throw new NotSupportedException (); }
\r
95 public virtual IWebProxy Proxy {
\r
96 get { throw new NotSupportedException (); }
\r
97 set { throw new NotSupportedException (); }
\r
100 public virtual Uri RequestUri {
\r
101 get { throw new NotSupportedException (); }
\r
102 set { throw new NotSupportedException (); }
\r
105 public virtual int Timeout {
\r
106 get { throw new NotSupportedException (); }
\r
107 set { throw new NotSupportedException (); }
\r
112 public virtual void Abort()
\r
114 throw new NotSupportedException ();
\r
117 public virtual IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)
\r
119 throw new NotSupportedException ();
\r
122 public virtual IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
\r
124 throw new NotSupportedException ();
\r
127 public static WebRequest Create (string requestUriString)
\r
129 if (requestUriString == null)
\r
130 throw new ArgumentNullException ("requestUriString");
\r
131 return Create (new Uri (requestUriString));
\r
134 public static WebRequest Create (Uri requestUri)
\r
136 if (requestUri == null)
\r
137 throw new ArgumentNullException ("requestUri");
\r
138 return GetCreator (requestUri.AbsoluteUri).Create (requestUri);
\r
141 public static WebRequest CreateDefault (Uri requestUri)
\r
143 if (requestUri == null)
\r
144 throw new ArgumentNullException ("requestUri");
\r
145 return GetCreator (requestUri.Scheme).Create (requestUri);
\r
148 public virtual Stream EndGetRequestStream (IAsyncResult asyncResult)
\r
150 throw new NotSupportedException ();
\r
153 public virtual WebResponse EndGetResponse (IAsyncResult asyncResult)
\r
155 throw new NotSupportedException ();
\r
158 public virtual Stream GetRequestStream()
\r
160 throw new NotSupportedException ();
\r
163 public virtual WebResponse GetResponse()
\r
165 throw new NotSupportedException ();
\r
168 void ISerializable.GetObjectData (SerializationInfo serializationInfo,
\r
169 StreamingContext streamingContext)
\r
171 throw new NotSupportedException ();
\r
174 public static bool RegisterPrefix (string prefix, IWebRequestCreate creator)
\r
176 if (prefix == null)
\r
177 throw new ArgumentNullException("prefix");
\r
178 if (creator == null)
\r
179 throw new ArgumentNullException("creator");
\r
181 lock (prefixes.SyncRoot) {
\r
182 if (prefixes.Contains (prefix))
\r
184 prefixes.Add (prefix.ToLower (), creator);
\r
189 private static IWebRequestCreate GetCreator (string prefix)
\r
191 int longestPrefix = -1;
\r
192 IWebRequestCreate creator = null;
\r
194 prefix = prefix.ToLower ();
\r
196 IDictionaryEnumerator e = prefixes.GetEnumerator ();
\r
197 while (e.MoveNext ()) {
\r
198 string key = e.Key as string;
\r
200 if (key.Length <= longestPrefix)
\r
203 if (!prefix.StartsWith (key))
\r
206 longestPrefix = key.Length;
\r
207 creator = (IWebRequestCreate) e.Value;
\r
210 if (creator == null)
\r
211 throw new NotSupportedException (prefix);
\r