static void TestMethod3() { ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; string url = "https://www.emeraldinsight.com/action/doSearch?AllField=computer&content=articlesChapters&cookie=I2KBRCK=1"; //post 请求 List <KeyValuePair <string, string> > pars = new List <KeyValuePair <string, string> >(); pars.Add(new KeyValuePair <string, string>("doi", "10.1108/al.1999.8.2.54.1")); pars.Add(new KeyValuePair <string, string>("doi", "10.1108/IJPCC-02-2017-0012")); pars.Add(new KeyValuePair <string, string>("format", "bibtex")); pars.Add(new KeyValuePair <string, string>("cookie", "I2KBRCK=1")); url = "https://www.emeraldinsight.com/action/downloadCitation"; var r = HTTPClientHelper.HttpPostRequestAsync(url, pars); File.WriteAllText(@"d:/mydata.html", r); if (r.Length > 50) { Console.WriteLine("ok"); } else { Console.WriteLine("empty"); } Console.Read(); }
public static async Task <string> GetItemDetails(string patToken, string ItemRootPath, string ItemFullPath, string AzureDevopsBaseURL, string branchname) { string responseContent = string.Empty; //use the httpclient using (var client = new HttpClient()) { HTTPClientHelper clientHelper = new HTTPClientHelper(AzureDevopsBaseURL); string baseURL = clientHelper.GetAzureDevopsItemURL(ItemFullPath.Replace("refs/", ""), branchname.Replace("refs/heads/", "")); client.BaseAddress = new Uri(baseURL); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", patToken); //connect to the REST endpoint HttpResponseMessage httpResponse = client.GetAsync("").Result; { responseContent = await httpResponse.Content.ReadAsStringAsync(); } } JObject json = responseContent != string.Empty ? JObject.Parse(responseContent) : null; //string FilePath = @"/Test/Release/TemplateSolution"; return(Convert.ToInt32(json["count"]) > 0 ? "edit" : "add"); }
public static async Task <string> GetLastCommitDetails(string patToken, string sourceBranchName, string AzureDevopsBaseURL) { string responseContent = string.Empty; //use the httpclient using (var client = new HttpClient()) { HTTPClientHelper clientHelper = new HTTPClientHelper(AzureDevopsBaseURL); string baseURL = clientHelper.GetAzureDevopsLastCommitURL(sourceBranchName.Replace("refs/", "")); client.BaseAddress = new Uri(baseURL); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", patToken); //connect to the REST endpoint HttpResponseMessage httpResponse = client.GetAsync("").Result; //check to see if we have a successful response if (httpResponse.IsSuccessStatusCode) { responseContent = await httpResponse.Content.ReadAsStringAsync(); } } JObject json = responseContent != string.Empty ? JObject.Parse(responseContent) : null; return(json?["value"][0]["objectId"].ToString()); }
/// <summary> /// 构造函数 /// </summary> public DataSynController(IHostingEnvironment env, IIdentityService identity, IHttpClientFactory httpClientFactory, IRepository <SysUser, long> sysUserRepository, IRepository <SysUsertrack, long> sysUserTrackRepository) { _appConfiguration = env.GetAppConfiguration(); _identity = identity; _sysUserRepository = sysUserRepository; _sysUserTrackRepository = sysUserTrackRepository; _httpClientFactory = httpClientFactory; _httpClient = new HTTPClientHelper(_httpClientFactory); }
/// <summary> /// Commit API Call /// </summary> /// <param name="commitInputDetails"></param> /// <returns></returns> public static async Task <string> Commit(string patToken, CommitObject commitInputDetails, Uri AzureDevopsBaseURL) { string responseContent = string.Empty; try { //use the httpclient using (var client = new HttpClient()) { if (AzureDevopsBaseURL != null) { HTTPClientHelper clientHelper = new HTTPClientHelper(AzureDevopsBaseURL.ToString()); client.BaseAddress = new Uri(clientHelper.GetAzureDevopsPushURL()); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", patToken); // Serialize our concrete class into a JSON String var stringPayload = JsonConvert.SerializeObject(commitInputDetails); // Wrap our JSON inside a StringContent which then can be used by the HttpClient class var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); //connect to the REST endpoint HttpResponseMessage httpResponse = client.PostAsync("", httpContent).Result; httpContent.Dispose(); //check to see if we have a successful response //if (httpResponse.IsSuccessStatusCode) { responseContent = await httpResponse.Content.ReadAsStringAsync(); } } } return(responseContent); } catch (Exception) { throw; } }
public static async Task <List <string> > GetBranches(string patToken, string AzureDevopsBaseURL) { string responseContent = string.Empty; //use the httpclient using (var client = new HttpClient()) { HTTPClientHelper clientHelper = new HTTPClientHelper(AzureDevopsBaseURL); string baseURL = clientHelper.GetAzureDevopsRefsURL(); client.BaseAddress = new Uri(baseURL); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", patToken); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", // Convert.ToBase64String( // System.Text.ASCIIEncoding.ASCII.GetBytes( // string.Format("{0}:{1}", "", patToken)))); //connect to the REST endpoint HttpResponseMessage httpResponse = client.GetAsync("").Result; //check to see if we have a successful response if (httpResponse.IsSuccessStatusCode) { responseContent = await httpResponse.Content.ReadAsStringAsync(); } else { const string message = "Probable Github pat token error"; throw new UnauthorizedAccessException(message); } } JObject json = responseContent != string.Empty ? JObject.Parse(responseContent) : null; List <string> refNames = json["value"].Select(x => x["name"].ToString()).ToList(); return(refNames); }