コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public bool PostClipboardToServer(string username, string password, string text, out string output)
        {
            bool ret = false;

            try
            {
                WebProxy wProxy = (WebProxy)WebProxy.GetDefaultProxy();
                wProxy.Credentials = new NetworkCredential("dan.perrett", "password", "MYANITE");
                wProxy.Credentials = (System.Net.NetworkCredential)System.Net.CredentialCache.DefaultCredentials;

                System.Net.GlobalProxySelection.Select = wProxy;
                string URI = "http://www.danperrett.com:8000/ClipBoardData";

                WebUpload wc = new WebUpload(5 * 60 * 1000);
                wc.Proxy = wProxy;

                SetAllowUnsafeHeaderParsing20();

                wc.Headers["Content-type"] = "application/x-www-form-urlencoded";

                text = text.Substring(0, text.Length - 2);
                text = text.Trim();
                NameValueCollection myNameValueCollection = new NameValueCollection();
                // Add necessary parameter/value pairs to the name/value container.
                myNameValueCollection.Add("name", username);
                myNameValueCollection.Add("password", password);
                myNameValueCollection.Add("data", text);

                wc.UploadValuesCompleted += new UploadValuesCompletedEventHandler(wc_UploadValuesCompleted);
                wc.UploadValuesAsync(new Uri(URI), myNameValueCollection);


                //output = System.Text.ASCIIEncoding.ASCII.GetString(ret_b);
                output = "complete";
                ret    = true;
            }
            catch
            {
                output = "Error";
            }

            return(ret);
        }
コード例 #2
0
        public bool PostToServer(string username, string password, string project, string filename, out string ret)
        {
            // filename = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Forest.jpg";
            try
            {
                WebProxy wProxy = (WebProxy)WebProxy.GetDefaultProxy();
                wProxy.Credentials = new NetworkCredential("dan.perrett", "password", "MYANITE");
                wProxy.Credentials = (System.Net.NetworkCredential)System.Net.CredentialCache.DefaultCredentials;
                // See what proxy is used for resource.
                //Uri resourceProxy = proxy.GetProxy(url);

                // WebProxy wProxy = new WebProxy("http://10.4.1.200:80");

                //wProxy.Credentials
                System.Net.GlobalProxySelection.Select = wProxy;
                string URI = "http://www.danperrett.com:8000/uploadFile";
                //  string myParamters = "project=" + project + "&datafile=" + System.Web.HttpUtility.UrlEncode(contents);

                WebUpload wc = new WebUpload(5 * 60 * 1000);
                wc.Proxy = wProxy;
                string[] file_s = filename.Split('\\');
                string   file   = file_s[file_s.Length - 1];
                //file = project + "/" + file;
                //file = file.Replace("/", "%2F");
                SetAllowUnsafeHeaderParsing20();

                wc.Headers["Content-type"]  = "image/jpg";
                wc.QueryString["directory"] = project + "/" + file;
                wc.QueryString["username"]  = username;
                wc.QueryString["password"]  = password;

                wc.UploadFileCompleted += new UploadFileCompletedEventHandler(wc_UploadFileCompleted);
                byte[] ret_b = wc.UploadFile(URI, filename);
                ret = System.Text.ASCIIEncoding.ASCII.GetString(ret_b);

                return(true);
            }
            catch
            {
                ret = "Unsuccessful";
                return(false);
            }
        }