예제 #1
0
        public void upload(string map, string input)
        {
            int redo = 0;

            MessageBox.Show("恭喜您成功解题!程序将上传您的解题思路至服务器进行统计研究\n若您有什么意见可以在帮助窗口中进行反馈,感谢您的合作。");
            while (redo <= 5)
            {
                try
                {
                    input = System.Text.RegularExpressions.Regex.Replace(input, "=======开始下载=======", "\0");
                    input = System.Text.RegularExpressions.Regex.Replace(input, "=======下载结束=======", "\0");
                    string postString = "?map=" + map + "&" + "code=" + input;             //这里即为传递的参数,可以用工具抓包分析,也可以自己分析,主要是form里面每一个name都要加进来
                    byte[] postData   = Encoding.UTF8.GetBytes(postString);                //编码,尤其是汉字,事先要看下抓取网页的编码方式
                    string url        = "http://wpcwzy.top/data/process.php" + postString; //地址
                    Console.WriteLine("Server URL:{0}", url);
                    WebClientEx webClient = new WebClientEx();
                    webClient.Timeout = 3500;
                    byte[] responseData = webClient.DownloadData(url);           //得到返回字符流
                    string srcString    = Encoding.UTF8.GetString(responseData); //解码
                    Console.WriteLine(srcString);
                    break;
                }
                catch (WebException)
                {
                    redo++;
                    Console.WriteLine("Retry:{0} Time(s)", redo);
                    continue;
                }
                catch (Exception ex)
                {
                    var notice   = Form1.form.airbrake.BuildNotice(ex);
                    var response = Form1.form.airbrake.NotifyAsync(notice).Result;
                    Console.WriteLine("Status: {0}, Id: {1}, Url: {2}", response.Status, response.Id, response.Url);
                    throw ex;
                }
            }
        }