예제 #1
0
        /// <summary>
        /// POST to Apisci
        /// </summary>
        /// <param name="reference">PNR</param>
        /// <param name="action">Booking complete, modified, inbound, outbound, canceled</param>
        /// <param name="data">Dictionary with email, bookingdate, depaturedate, PNR, mobile, services</param>
        public static void Send(string reference, string action, IDictionary <string, string> data)
        {
            //var serviceUrl = ConfigurationManager.AppSettings["Apisci.ServiceFacade"];
            //var apiKey = ConfigurationManager.AppSettings["Apisci.ApiKey"];

            var serviceUrl = @"http://localhost:40170/api/Apisci";
            var apiKey     = "12345";

            var httpClient = new EasyHttp.Http.HttpClient
            {
                ThrowExceptionOnHttpError = false
            };


            var response = httpClient.Post(serviceUrl, new
            {
                Reference = reference,
                ApiKey    = apiKey,
                Action    = action,
                Data      = data
            }, "application/json");


            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new SendErrorException();
            }
        }
 public void ServerReturnsAResponse()
 {
     CassiniDevServer server = new CassiniDevServer();
     server.StartServer(Path.Combine(Environment.CurrentDirectory, @"..\..\..\MvcMusicStore"));
     string url = server.NormalizeUrl("/");
     Console.WriteLine(url);
     var client = new EasyHttp.Http.HttpClient();
     var response = client.Get(url);
     Console.WriteLine(response.RawText);
     Assert.IsFalse(string.IsNullOrEmpty(response.RawText));
 }
예제 #3
0
        /// <summary>
        /// Posts message and date to server
        /// </summary>
        /// <param name="message">message</param>
        /// <returns>Status code of the request</returns>
        public HttpStatusCode Post(string message)
        {
            var httpClient = new EasyHttp.Http.HttpClient();

            //Restricting posts to server
            httpClient.Request.AddExtraHeader("X-API-KEY", _apiKey);

            var response = httpClient.Post(_serviceUrl, new
            {
                TextMessage = message,
                DateTime    = DateTime.Now
            }, "application/json");

            return(response.StatusCode);
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("开始检查文件数据...");
            var files = Directory.GetFiles(FilePath);
            List <CheckFileInfo> fileInfos = new List <CheckFileInfo>();

            foreach (var item in files)
            {
                var file = new FileInfo(item);//遍历文件信息
                fileInfos.Add(new CheckFileInfo()
                {
                    FileName     = file.Name,
                    FileMd5Value = GetMD5HashFromFile(item)
                });
            }

            Console.WriteLine("数据检查完成,开始和服务器数据比对...");
            EasyHttp.Http.HttpClient htpclient = new EasyHttp.Http.HttpClient();
            var response       = htpclient.Post(UpdateUrl, fileInfos, EasyHttp.Http.HttpContentTypes.ApplicationJson);
            var updateFileList = JsonConvert.DeserializeObject <List <UpdateFileInfo> >(response.RawText);

            Console.WriteLine("获得文件完成,开始更新...");
            WebClient webClient = new WebClient();

            if (updateFileList == null)
            {
                Console.WriteLine("无需更新,即将结束更新程序");
                Thread.Sleep(1000);
                return;
            }
            foreach (var item in updateFileList)
            {
                try
                {
                    Console.WriteLine($"正在下载:{item.FileName}");
                    webClient.DownloadFile(item.Url, FilePath + item.FileName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"程序出现错误:{ex.ToString()}");
                    Console.ReadKey();
                }
            }
            Console.WriteLine("更新完成,程序即将关闭");
            Thread.Sleep(1000);
        }
        public void FiveTrackNamesAppearOnHomepage()
        {
            CassiniDevServer server = new CassiniDevServer();
            server.StartServer(Path.Combine(Environment.CurrentDirectory, @"..\..\..\MvcMusicStore"));
            string url = server.NormalizeUrl("/");
            var client = new EasyHttp.Http.HttpClient();
            var response = client.Get(url);
            var html = response.RawText;

            StringAssert.Contains("The Best Of Men At Work", html);
            StringAssert.Contains("For Those About To Rock We Salute You", html);
            StringAssert.Contains("Let There Be Rock", html);
            StringAssert.Contains("Balls to the Wall", html);
            StringAssert.Contains("Restless and Wild", html);

            server.StopServer();
        }
예제 #6
0
        /// <summary>
        /// HTTP POST to Apisci
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="action"></param>
        /// <param name="data"></param>
        protected override void Send(string reference, string action, IDictionary <string, string> data)
        {
            //var serviceUrl = ConfigurationManager.AppSettings["Apisci.Service"];
            //var apiKey = ConfigurationManager.AppSettings["Apisci.ApiKey"];

            var serviceUrl = @"http://localhost:40170/api/Apisci";
            var apiKey     = "12345";

            var httpClient = new EasyHttp.Http.HttpClient
            {
                ThrowExceptionOnHttpError = false
            };


            var response = httpClient.Post(serviceUrl, new
            {
                Reference = reference,
                ApiKey    = apiKey,
                Action    = action,
                Data      = data
            }, "application/json");

            if (response.StatusCode != HttpStatusCode.OK)
            {
                //Saving processed data to database
                var processedData = new ProcessedData
                {
                    Reference = reference,
                    Action    = action,
                    Data      = JsonConvert.SerializeObject(data)
                };

                DataRepository.AddData(processedData);
                DataRepository.Save();

                throw new SendErrorException();
            }
        }
예제 #7
0
        //
        // GET: /Search/

        public ActionResult Index()
        {
            #region 搜索后返回页面内容

            if (Request.QueryString["q"] != null && Request.QueryString["q"].ToString() != "")
            {
                var url = string.Format("http://www.google.com/search{0}", Request.Url.Query);
                EasyHttp.Http.HttpClient httpclient = new EasyHttp.Http.HttpClient();
                var response = httpclient.Get(url);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(Content(response.RawText));
                }
                else
                {
                    return(Content("error"));
                }
            }

            #endregion

            return(View());
        }