Exemplo n.º 1
0
 public ruleForm(AlpineBitsServer srvAlpineBits)
 {
     InitializeComponent();
     myServer = srvAlpineBits;
     ReadServerParams();
     this.Text = "Certification";
 }
Exemplo n.º 2
0
        public static async Task <AlpineBitsResponse> ProcessRequest(AlpineBitsServer CallServer, string CallAction, string CallParam = "")
        {
            var StatusCode = "";
            var Response   = new AlpineBitsResponse();

            if (CallParam.Length > 0)
            {
                CallParam = CallParam.Replace("{HOTELCODE}", CallServer.HotelCode);
                CallParam = CallParam.Replace("{HOTELNAME}", "Hotel AlpineBits");
                CallParam = CallParam.Replace("{YEAR}", DateTime.Now.Year.ToString());
            }
            // OTA_INVENTORY
            var content = new MultipartFormDataContent(Guid.NewGuid().ToString());

            //Note: it's a best practice to use double-quotes, even when the name doesn't contain spaces:
            content.Add(new StringContent(CallAction), "\"action\"");
            string RequestXML = CallParam;

            if (CallAction != "getVersion" && CallAction != "getCapabilities")
            {
                content.Add(new StringContent(CallParam), "\"request\"");
            }
            HttpResponseMessage result;

            // Client: acceptEncoding gzIP
            HttpClientHandler clHandler = new HttpClientHandler();

            if (CallServer.AcceptResponseGZIPEncoded)
            {
                clHandler.AutomaticDecompression = DecompressionMethods.GZip;
            }

            var headersRequest  = "";
            var headersResponse = "";

            using (var client = new HttpClient(clHandler))
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(string.Format("{0}:{1}", CallServer.UserName, CallServer.Password))));
                client.DefaultRequestHeaders.Add("X-AlpineBits-ClientProtocolVersion", CallServer.X_AlpineBits_ProtocolVersion);
                client.DefaultRequestHeaders.Add("X-AlpineBits-ClientID", CallServer.X_AlpineBits_ClientID);
                if (CallServer.InvokeZipped)
                {
                    result = await client.PostAsync(CallServer.ServerURL, new CompressedContent(content, "gzip"));
                }
                else
                {
                    //                    client.DefaultRequestHeaders.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
                    //                    client.DefaultRequestHeaders.TransferEncoding.Add(new TransferCodingHeaderValue("gzip"));
                    result = await client.PostAsync(CallServer.ServerURL, content);
                }
                headersResponse   = result.Headers.ToString() + result.Content.Headers.ToString();
                Response.Encoding = result.Content.Headers.ContentType.ToString();

                headersRequest = client.DefaultRequestHeaders.ToString();
                StatusCode     = result.StatusCode.ToString("D") + " " + result.StatusCode.ToString();
            }
            Response.StatusCode      = StatusCode;
            Response.ResponseHeaders = headersResponse;
            if (result.StatusCode == HttpStatusCode.OK)
            {
                Response.ResponseBody = await result.Content.ReadAsStringAsync();
            }
            else
            {
                Response.ResponseBody = await result.Content.ReadAsStringAsync();

//                Response.ResponseBody = @"Request failed. Status code: " + result.StatusCode + " " + result.StatusCode.ToString("D") + ". Message Content: " + result.Content.ReadAsStringAsync().Result;
            }

            return(Response);
        }