示例#1
0
        public string SendData(string ClientCode, string EventCode, string urlToPost, string dataToPost, string contentType, int TimeOutInMsSecs, string ID, string IDExtra, string HeaderAuthorizationValue, string expectedResult = "", int dealyJob = 0, string parentJobId = "")
        {
            if (dealyJob != 0)
            {
                System.Threading.Thread.Sleep(dealyJob);
            }
            using (CustomWebClient wc = new CustomWebClient(TimeOutInMsSecs))
            {
                //Header Autorization Value
                if (!string.IsNullOrEmpty(HeaderAuthorizationValue))
                {
                    wc.Headers[HttpRequestHeader.Authorization] = HeaderAuthorizationValue;
                }

                wc.Headers[HttpRequestHeader.ContentType] = contentType;
                wc.Headers.Add("WebhookHub_ClientCode", ClientCode);
                wc.Headers.Add("WebhookHub_EventCode", EventCode);
                wc.Headers.Add("WebhookHub_ID", ID);
                wc.Headers.Add("WebhookHub_IDExtra", IDExtra);
                string HtmlResult = wc.UploadString(new Uri(urlToPost), dataToPost);

                if (!string.IsNullOrEmpty(expectedResult) && HtmlResult != expectedResult)
                {
                    throw new Exception("[Unexpected content result]");
                }
                return(HtmlResult);
            }
        }
示例#2
0
        public int POST(string url, object data)
        {
            try {
                wc.UploadString(url, JsonConvert.SerializeObject(data));
            } catch (WebException ex) {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpWebResponse res = (HttpWebResponse)ex.Response;
                    if (res == null)
                    {
                        return(0);
                    }

                    return((int)res.StatusCode);
                }
                return(0);
            }
            return(200);
        }
示例#3
0
        public string PostJson(string url, string json, int timeoutInSeconds, IEnumerable <Tuple <string, string> > additionalHeaders = null)
        {
            string response;

            using (var webClient = new CustomWebClient(timeoutInSeconds))
            {
                webClient.Headers.Add(HttpRequestHeader.ContentType, JsonMimeType);

                SetAdditionalHeaders(additionalHeaders, webClient);

                response = webClient.UploadString(url, json);
            }

            return(response);
        }
示例#4
0
        /// <summary>
        /// Execute HTTP request
        /// </summary>
        /// <param name="url">address</param>
        /// <param name="method">HTTP Method Definitions</param>
        /// <returns>Response object</returns>
        public HttpResponse execute(String url, string method)
        {
            try
            {
                _httpClient.UploadString(url, method, String.Empty);
            }
            catch (WebException ex)
            {
                if (ex.Response != null)
                {
                    var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
                    return(new HttpResponse(statusCode, ex.Message));
                }

                throw new WebException(ex.Message, ex);
            }

            return(new HttpResponse(HttpStatusCode.OK, "Request Succeeded"));
        }