示例#1
0
        public HttpWebResponse Submit(Uri uri, FSpot.ProgressItem progress_item)
        {
            this.Progress = progress_item;
            Request       = (HttpWebRequest)WebRequest.Create(uri);
            CookieCollection cookie_collection = Cookies.GetCookies(uri);

            if (uri.UserInfo != null && uri.UserInfo != String.Empty)
            {
                NetworkCredential cred = new NetworkCredential();
                cred.GetCredential(uri, "basic");
                CredentialCache credcache = new CredentialCache();
                credcache.Add(uri, "basic", cred);

                Request.PreAuthenticate = true;
                Request.Credentials     = credcache;
            }

            Request.ServicePoint.Expect100Continue = expect_continue;

            Request.CookieContainer = new CookieContainer();
            foreach (Cookie c in cookie_collection)
            {
                if (SuppressCookiePath)
                {
                    Request.CookieContainer.Add(new Cookie(c.Name, c.Value));
                }
                else
                {
                    Request.CookieContainer.Add(c);
                }
            }

            Request.Method = "POST";
            Request.Headers["Accept-Charset"] = "utf-8;";

            //Request.UserAgent = "F-Spot Gallery Remote Client";
            Request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1";

            Request.Proxy = WebProxy.GetDefaultProxy();

            if (multipart)
            {
                GenerateBoundary();
                Request.ContentType = "multipart/form-data; boundary=" + boundary;
                Request.Timeout     = Request.Timeout * 3;

                long length = 0;
                for (int i = 0; i < Items.Count; i++)
                {
                    FormItem item = (FormItem)Items[i];

                    length += MultipartLength(item);
                }
                length += end_boundary.Length + 2;

                //Request.Headers["My-Content-Length"] = length.ToString ();
                if (Buffer == false)
                {
                    Request.ContentLength             = length;
                    Request.AllowWriteStreamBuffering = false;
                }
            }
            else
            {
                Request.ContentType = "application/x-www-form-urlencoded";
            }

            stream_writer = new StreamWriter(Request.GetRequestStream());

            first_item = true;
            for (int i = 0; i < Items.Count; i++)
            {
                FormItem item = (FormItem)Items[i];

                Write(item);
            }

            if (multipart)
            {
                stream_writer.Write(end_boundary + "\r\n");
            }

            stream_writer.Flush();
            stream_writer.Close();

            HttpWebResponse response;

            try {
                response = (HttpWebResponse)Request.GetResponse();

                //Console.WriteLine ("found {0} cookies", response.Cookies.Count);

                foreach (Cookie c in response.Cookies)
                {
                    Cookies.Add(c);
                }
            } catch (WebException e) {
                if (e.Status == WebExceptionStatus.ProtocolError &&
                    ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.ExpectationFailed && expect_continue)
                {
                    e.Response.Close();
                    expect_continue = false;
                    return(Submit(uri, progress_item));
                }

                throw new WebException(Mono.Unix.Catalog.GetString("Unhandled exception"), e);
            }

            return(response);
        }
		public HttpWebResponse Submit (Uri uri, FSpot.ProgressItem progress_item) 
		{
			this.Progress = progress_item;
			Request = (HttpWebRequest) WebRequest.Create (uri);
			CookieCollection cookie_collection = Cookies.GetCookies (uri);
	
			if (uri.UserInfo != null && uri.UserInfo != String.Empty) {
				NetworkCredential cred = new NetworkCredential ();
				cred.GetCredential (uri, "basic");
				CredentialCache credcache = new CredentialCache();
				credcache.Add(uri, "basic", cred);
				
				Request.PreAuthenticate = true;
				Request.Credentials = credcache;	
			}
	
			Request.ServicePoint.Expect100Continue = expect_continue;
	
			Request.CookieContainer = new CookieContainer ();
			foreach (Cookie c in cookie_collection) {
				if (SuppressCookiePath) 
					Request.CookieContainer.Add (new Cookie (c.Name, c.Value));
				else
					Request.CookieContainer.Add (c);
			}
	
			Request.Method = "POST";
			Request.Headers["Accept-Charset"] = "utf-8;";
			
			//Request.UserAgent = "F-Spot Gallery Remote Client";
			Request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1";
	
			Request.Proxy = WebProxy.GetDefaultProxy ();
	
			if (multipart) {
				GenerateBoundary ();
				Request.ContentType = "multipart/form-data; boundary=" + boundary;
				Request.Timeout = Request.Timeout * 3;
	
				long length = 0;
				for (int i = 0; i < Items.Count; i++) {
					FormItem item = (FormItem)Items[i];
					
					length += MultipartLength (item);
				}
				length += end_boundary.Length + 2;
				
				//Request.Headers["My-Content-Length"] = length.ToString ();
				if (Buffer == false) {
					Request.ContentLength = length;	
					Request.AllowWriteStreamBuffering = false;
				}
			} else {
				Request.ContentType = "application/x-www-form-urlencoded";
			}
			
			stream_writer = new StreamWriter (Request.GetRequestStream ());
			
			first_item = true;
			for (int i = 0; i < Items.Count; i++) {
				FormItem item = (FormItem)Items[i];
				
				Write (item);
			}
			
			if (multipart)
				stream_writer.Write (end_boundary + "\r\n");
			
			stream_writer.Flush ();
			stream_writer.Close ();
	
			HttpWebResponse response; 
	
			try {
				response = (HttpWebResponse) Request.GetResponse ();
				
				//Console.WriteLine ("found {0} cookies", response.Cookies.Count);
				
				foreach (Cookie c in response.Cookies) {
					Cookies.Add (c);
				}
			} catch (WebException e) {
				if (e.Status == WebExceptionStatus.ProtocolError 
				    && ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.ExpectationFailed && expect_continue) {
					e.Response.Close ();
					expect_continue = false;
					return Submit (uri, progress_item);
				}
				
				throw new WebException (Mono.Unix.Catalog.GetString ("Unhandled exception"), e);
			}
	
			return response;
		}
示例#3
0
 public HttpWebResponse Submit(string url, FSpot.ProgressItem item)
 {
     return(Submit(new Uri(url), item));
 }