class to pass request parameters
Ejemplo n.º 1
0
        public string UploadValues(RequestParams requestParam)
        {
            string responseString = "true";
            Utility.Check.IsNotNull(requestParam, "RequestParams");
            //  call the api with data file 
            using (WebClientRequest client = new WebClientRequest(requestParam))
            {
                client.Headers.Add("Authorization", HttpContext.Current.Request.Cookies[Constants.APPJWTCOOKIETOKEN].Value);
                byte[] response = client.UploadValues(new Uri(requestParam.RequestURL), requestParam.RequestMode.ToString(), requestParam.Values);
                this.RedirectionURL =  client.ResponseHeaders["Location"];
                responseString = Encoding.UTF8.GetString(response);
            }

            return responseString;
        }
Ejemplo n.º 2
0
 public WebClientRequest(RequestParams requestParam)
 {
     this.AllowAutoRedirect = requestParam.AllowAutoRedirect;
 }
        /// <summary>
        /// Method to set Request Details
        /// </summary>
        /// <param name="requestParam">Request parameters</param>
        /// <param name="repositoryCredentials">Repository Credentials</param>
        public void SetRequestDetails(RequestParams requestParam, RepositoryCredentials repositoryCredentials = null)
        {
            Utility.Check.IsNotNull(requestParam, "RequestParams");

            var jwtToken = HttpContext.Current.Request.Cookies[Constants.APPJWTCOOKIETOKEN].Value;
            WebRequest request = System.Net.WebRequest.Create(requestParam.RequestURL);

            webRequest = request as HttpWebRequest;

            webRequest.Headers.Add(HttpRequestHeader.Authorization, jwtToken);

            if (repositoryCredentials != null)
            {
                string serilizedRepositoryCredentials = new JavaScriptSerializer().Serialize(repositoryCredentials);
                webRequest.Headers.Add(Utility.Constants.RepositoryCredentialHeaderName, serilizedRepositoryCredentials);
            }

            webRequest.Method = requestParam.RequestMode.ToString();
            if (!string.IsNullOrEmpty(requestParam.ContentType))
            {
                webRequest.ContentType = requestParam.ContentType;
            }
            if (requestParam.TimeOut > 0)
            {
                webRequest.Timeout = requestParam.TimeOut;
            }

            webRequest.AllowAutoRedirect = requestParam.AllowAutoRedirect;

            // TODO
            if (requestParam.Values != null && requestParam.Values.Count>0)
            {
                UTF8Encoding encoding = new UTF8Encoding();
                data = encoding.GetBytes(requestParam.Values[0]);
                request.ContentLength = data.Length;
                Stream postStream = webRequest.GetRequestStream();
                postStream.Write(data, 0, data.Length);
                postStream.Close();
            }
        }