public async System.Threading.Tasks.Task <ICustomActivityResult> Execute() { HttpClient client = new HttpClient(); ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); UriBuilder UriBuilder = new UriBuilder(endPoint); UriBuilder.Path = uriBuilderPath; UriBuilder.Query = AyehuHelper.queryStringBuilder(queryStringArray); HttpRequestMessage myHttpRequestMessage = new HttpRequestMessage(new HttpMethod(httpMethod), UriBuilder.ToString()); if (contentType == "application/x-www-form-urlencoded") { myHttpRequestMessage.Content = AyehuHelper.formUrlEncodedContent(postData); } else if (string.IsNullOrEmpty(postData) == false) { if (omitJsonEmptyorNull) { myHttpRequestMessage.Content = new StringContent(AyehuHelper.omitJsonEmptyorNull(postData), Encoding.UTF8, "application/json"); } else { myHttpRequestMessage.Content = new StringContent(postData, Encoding.UTF8, contentType); } } foreach (KeyValuePair <string, string> headeritem in headers) { client.DefaultRequestHeaders.Add(headeritem.Key, headeritem.Value); } HttpResponseMessage response = client.SendAsync(myHttpRequestMessage).Result; switch (response.StatusCode) { case HttpStatusCode.NoContent: case HttpStatusCode.Created: case HttpStatusCode.Accepted: case HttpStatusCode.OK: { if (string.IsNullOrEmpty(response.Content.ReadAsStringAsync().Result) == false) { return(this.GenerateActivityResult(response.Content.ReadAsStringAsync().Result, Jsonkeypath)); } else { return(this.GenerateActivityResult("Success")); } } default: { if (string.IsNullOrEmpty(response.Content.ReadAsStringAsync().Result) == false) { throw new Exception(response.Content.ReadAsStringAsync().Result); } else if (string.IsNullOrEmpty(response.ReasonPhrase) == false) { throw new Exception(response.ReasonPhrase); } else { throw new Exception(response.StatusCode.ToString()); } } } }
public async System.Threading.Tasks.Task <ICustomActivityResult> Execute() { HttpClient client = new HttpClient(); ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); UriBuilder UriBuilder = new UriBuilder(endPoint); UriBuilder.Path = "/santaba/rest" + uriBuilderPath; UriBuilder.Query = AyehuHelper.queryStringBuilder(queryStringArray); HttpRequestMessage myHttpRequestMessage = new HttpRequestMessage(new HttpMethod(httpMethod), UriBuilder.ToString()); string data = postData; if (string.IsNullOrEmpty(postData) == false) { if (omitJsonEmptyorNull) { data = AyehuHelper.omitJsonEmptyorNull(postData); } myHttpRequestMessage.Content = new StringContent(data, Encoding.UTF8, contentType); } var epoch = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds; var authHeaderValue = string.Format("LMv1 {0}:{1}:{2}", accessid, GenerateSignature(epoch, httpMethod, data, uriBuilderPath, password1), epoch); client.DefaultRequestHeaders.Add("Authorization", authHeaderValue); client.DefaultRequestHeaders.Add("X-Version", "2"); HttpResponseMessage response = client.SendAsync(myHttpRequestMessage).Result; switch (response.StatusCode) { case HttpStatusCode.NoContent: case HttpStatusCode.Created: case HttpStatusCode.Accepted: case HttpStatusCode.OK: { if (string.IsNullOrEmpty(response.Content.ReadAsStringAsync().Result) == false) { return(this.GenerateActivityResult(response.Content.ReadAsStringAsync().Result, Jsonkeypath)); } else { return(this.GenerateActivityResult("Success")); } } default: { if (string.IsNullOrEmpty(response.Content.ReadAsStringAsync().Result) == false) { throw new Exception(response.Content.ReadAsStringAsync().Result); } else if (string.IsNullOrEmpty(response.ReasonPhrase) == false) { throw new Exception(response.ReasonPhrase); } else { throw new Exception(response.StatusCode.ToString()); } } } }