当前位置: 首页>>代码示例>>C#>>正文


C# WebClient.TrimStart方法代码示例

本文整理汇总了C#中System.Net.WebClient.TrimStart方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.TrimStart方法的具体用法?C# WebClient.TrimStart怎么用?C# WebClient.TrimStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了WebClient.TrimStart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddEventWithPhoto

 public void AddEventWithPhoto()
 {
     bool s = false;
     dynamic ev;
     var Wc = new WebClient();
     Wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
     var firstdata = "grant_type=password&username=" + "TestUserName" + "&password=" + "TestPassword361";
     var result1 = Wc.UploadString(SiteUrl + TokenUrl, firstdata);
     JObject o1 = JObject.Parse(result1);
     var token = o1["access_token"].Value<string>();
     Wc = new WebClient();
     Wc.Encoding = Encoding.UTF8;
     Wc.Headers.Add("Content-Type", "application/json");
     Wc.Headers.Add("Authorization", "Bearer " + token);
     string sdata;
     var photoIds = new string[0];
     var url = new WebClient().DownloadString(new Uri(SiteUrl + "api/Endpoints/GetUploadUrl/AddEvent"));
     url = url.Trim(new char[] { '\"' });
     url = url.TrimStart(new char[] { '/' });
     using (var client = new HttpClient())
     {
         MultipartFormDataContent form = new MultipartFormDataContent();
         client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
         var fs = new FileStream("C:\\Users\\Александр\\Desktop\\kompot.jpg", FileMode.Open);
         form.Add(new StreamContent(fs), "file", "file.jpg");
         fs = new FileStream("C:\\Users\\Александр\\Desktop\\qRISsLk7j3E.jpg", FileMode.Open);
         form.Add(new StreamContent(fs), "file", "file.jpg");
         var response = client.PostAsync(SiteUrl + url, form).Result;
         sdata = response.Content.ReadAsStringAsync().Result;
     }
     using (var client = new HttpClient())
     {
         client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
         var content = new StringContent(sdata, Encoding.UTF8, "application/json");
         var response = client.PostAsync(SiteUrl
                                 + "api/Endpoints/SaveUploadedFile/AddEvent", content).Result;
         sdata = response.Content.ReadAsStringAsync().Result;
         photoIds = JArray.Parse(sdata).Select(tok => (tok as JObject)["Id"].Value<string>()).ToArray();
     }
     try
     {
         var time = System.DateTime.Now.ToString("u");
         var data = JsonConvert.SerializeObject(new
         {
             Latitude = 76,
             Longitude = 92,
             Description = "TestEvent",
             EventDate = time,
             PhotoIds = photoIds
         });
         var result = Wc.UploadString(SiteUrl + AddEventUrl, data);
     }
     catch(WebException we)
     {
         Assert.Fail(we.Message);
     }
 }
开发者ID:nbIxMaN,项目名称:HomeWork,代码行数:57,代码来源:UnitTest1.cs


注:本文中的System.Net.WebClient.TrimStart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。