2 // System.Net.WebRequest
\r
5 // Lawrence Pit (loz@cable.a2000.nl)
\r
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
\r
31 using System.Collections.Specialized;
\r
32 using System.Configuration;
\r
34 using System.Runtime.Serialization;
\r
36 using System.Net.Configuration;
\r
39 namespace System.Net
\r
42 public abstract class WebRequest : MarshalByRefObject, ISerializable
\r
44 static HybridDictionary prefixes = new HybridDictionary ();
\r
48 static WebRequest ()
\r
50 #if NET_2_0 && CONFIGURATION_DEP
\r
51 object cfg = ConfigurationManager.GetSection ("system.net/webRequestModules");
\r
52 WebRequestModulesSection s = cfg as WebRequestModulesSection;
\r
54 foreach (WebRequestModuleElement el in
\r
55 s.WebRequestModules)
\r
56 AddPrefix (el.Prefix, el.Type);
\r
60 ConfigurationSettings.GetConfig ("system.net/webRequestModules");
\r
63 protected WebRequest ()
67 protected WebRequest (SerializationInfo serializationInfo, StreamingContext streamingContext)
\r
73 public virtual string ConnectionGroupName {
\r
74 get { throw new NotImplementedException (); }
\r
75 set { throw new NotImplementedException (); }
\r
78 public virtual long ContentLength {
\r
79 get { throw new NotImplementedException (); }
\r
80 set { throw new NotImplementedException (); }
\r
83 public virtual string ContentType {
\r
84 get { throw new NotImplementedException (); }
\r
85 set { throw new NotImplementedException (); }
\r
88 public virtual ICredentials Credentials {
\r
89 get { throw new NotImplementedException (); }
\r
90 set { throw new NotImplementedException (); }
\r
93 public virtual WebHeaderCollection Headers {
\r
94 get { throw new NotImplementedException (); }
\r
95 set { throw new NotImplementedException (); }
\r
98 public virtual string Method {
\r
99 get { throw new NotImplementedException (); }
\r
100 set { throw new NotImplementedException (); }
\r
103 public virtual bool PreAuthenticate {
\r
104 get { throw new NotImplementedException (); }
\r
105 set { throw new NotImplementedException (); }
\r
108 public virtual IWebProxy Proxy {
\r
109 get { throw new NotImplementedException (); }
\r
110 set { throw new NotImplementedException (); }
\r
113 public virtual Uri RequestUri {
\r
114 get { throw new NotImplementedException (); }
\r
117 public virtual int Timeout {
\r
118 get { throw new NotImplementedException (); }
\r
119 set { throw new NotImplementedException (); }
\r
124 public virtual void Abort()
\r
126 throw new NotImplementedException ();
\r
129 public virtual IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)
\r
131 throw new NotImplementedException ();
\r
134 public virtual IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
\r
136 throw new NotImplementedException ();
\r
139 public static WebRequest Create (string requestUriString)
\r
141 if (requestUriString == null)
\r
142 throw new ArgumentNullException ("requestUriString");
\r
143 return Create (new Uri (requestUriString));
\r
146 public static WebRequest Create (Uri requestUri)
\r
148 if (requestUri == null)
\r
149 throw new ArgumentNullException ("requestUri");
\r
150 return GetCreator (requestUri.AbsoluteUri).Create (requestUri);
\r
153 public static WebRequest CreateDefault (Uri requestUri)
\r
155 if (requestUri == null)
\r
156 throw new ArgumentNullException ("requestUri");
\r
157 return GetCreator (requestUri.Scheme).Create (requestUri);
\r
160 public virtual Stream EndGetRequestStream (IAsyncResult asyncResult)
\r
162 throw new NotImplementedException ();
\r
165 public virtual WebResponse EndGetResponse (IAsyncResult asyncResult)
\r
167 throw new NotImplementedException ();
\r
170 public virtual Stream GetRequestStream()
\r
172 throw new NotImplementedException ();
\r
175 public virtual WebResponse GetResponse()
\r
177 throw new NotImplementedException ();
\r
180 void ISerializable.GetObjectData (SerializationInfo serializationInfo,
\r
181 StreamingContext streamingContext)
\r
183 throw new NotSupportedException ();
\r
186 public static bool RegisterPrefix (string prefix, IWebRequestCreate creator)
\r
188 if (prefix == null)
\r
189 throw new ArgumentNullException("prefix");
\r
190 if (creator == null)
\r
191 throw new ArgumentNullException("creator");
\r
193 lock (prefixes.SyncRoot) {
\r
194 string lowerCasePrefix = prefix.ToLower ();
\r
195 if (prefixes.Contains (lowerCasePrefix))
\r
197 prefixes.Add (lowerCasePrefix, creator);
\r
202 private static IWebRequestCreate GetCreator (string prefix)
\r
204 int longestPrefix = -1;
\r
205 IWebRequestCreate creator = null;
\r
207 prefix = prefix.ToLower ();
\r
209 IDictionaryEnumerator e = prefixes.GetEnumerator ();
\r
210 while (e.MoveNext ()) {
\r
211 string key = e.Key as string;
\r
213 if (key.Length <= longestPrefix)
\r
216 if (!prefix.StartsWith (key))
\r
219 longestPrefix = key.Length;
\r
220 creator = (IWebRequestCreate) e.Value;
\r
223 if (creator == null)
\r
224 throw new NotSupportedException (prefix);
\r
229 internal static void ClearPrefixes ()
\r
234 internal static void RemovePrefix (string prefix)
\r
236 prefixes.Remove (prefix);
\r
239 internal static void AddPrefix (string prefix, string typeName)
\r
241 Type type = Type.GetType (typeName);
\r
243 throw new ConfigurationException (String.Format ("Type {0} not found", typeName));
\r
244 AddPrefix (prefix, type);
\r
247 internal static void AddPrefix (string prefix, Type type)
\r
249 object o = Activator.CreateInstance (type, true);
\r
250 prefixes [prefix] = o;
\r