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


C# HttpClient.AddFakeHeaders方法代码示例

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


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

示例1: Osu

            public async Task Osu(IUserMessage umsg, string usr, [Remainder] string mode = null)
            {
                var channel = (ITextChannel)umsg.Channel;

                if (string.IsNullOrWhiteSpace(usr))
                    return;

                using (HttpClient http = new HttpClient())
                {
                    try
                    {
                        var m = 0;
                        if (!string.IsNullOrWhiteSpace(mode))
                        {
                            m = ResolveGameMode(mode);
                        }
                        http.AddFakeHeaders();
                        var res = await http.GetStreamAsync(new Uri($"http://lemmmy.pw/osusig/sig.php?uname={ usr }&flagshadow&xpbar&xpbarhex&pp=2&mode={m}")).ConfigureAwait(false);

                        MemoryStream ms = new MemoryStream();
                        res.CopyTo(ms);
                        ms.Position = 0;
                        await channel.SendFileAsync(ms, $"{usr}.png", $"🎧 **Profile Link: **https://osu.ppy.sh/u/{Uri.EscapeDataString(usr)}\n`Image provided by https://lemmmy.pw/osusig`").ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        await channel.SendMessageAsync("💢 Failed retrieving osu signature :\\").ConfigureAwait(false);
                        _log.Warn(ex, "Osu command failed");
                    }
                }
            }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:31,代码来源:OsuCommands.cs

示例2: GetCookies

        public static CookieCollection GetCookies(string url)
        {
            CookieContainer container = new CookieContainer();

            HttpResponseMessage res;
            using (var handler = new HttpClientHandler() { CookieContainer = container })
            using (var http = new HttpClient(handler))
            {
                http.AddFakeHeaders();
                http.DefaultRequestHeaders.Add("ContentType", "text/html");
                res = http.GetAsync(url).GetAwaiter().GetResult();
            }
            var response = res.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            
            return container.GetCookies(res.RequestMessage.RequestUri);
        }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:16,代码来源:Utils.cs

示例3: RefreshAnilistToken

 private async Task RefreshAnilistToken()
 {
     if (DateTime.Now - lastRefresh > TimeSpan.FromMinutes(29))
         lastRefresh = DateTime.Now;
     else
     {
         return;
     }
     var headers = new Dictionary<string, string> {
         {"grant_type", "client_credentials"},
         {"client_id", "kwoth-w0ki9"},
         {"client_secret", "Qd6j4FIAi1ZK6Pc7N7V4Z"},
     };
     using (var http = new HttpClient())
     {
         http.AddFakeHeaders();
         var formContent = new FormUrlEncodedContent(headers);
         var response = await http.PostAsync("http://anilist.co/api/auth/access_token", formContent).ConfigureAwait(false);
         var stringContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
         anilistToken = JObject.Parse(stringContent)["access_token"].ToString();
     }
     
 }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:23,代码来源:AnimeSearchCommands.cs

示例4: GetE621ImageLink

 public static async Task<string> GetE621ImageLink(string tags)
 {
     try
     {
         using (var http = new HttpClient())
         {
             http.AddFakeHeaders();
             var data = await http.GetStreamAsync("http://e621.net/post/index.xml?tags=" + Uri.EscapeUriString(tags) + "%20order:random&limit=1");
             var doc = XDocument.Load(data);
             return doc.Descendants("file_url").FirstOrDefault().Value;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error in e621 search: \n" + ex);
         return "Error, do you have too many tags?";
     }
 }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:18,代码来源:NSFW.cs

示例5: GetGelbooruImageLink

        public static async Task<string> GetGelbooruImageLink(string tag)
        {
            using (var http = new HttpClient())
            {
                http.AddFakeHeaders();

                var webpage = await http.GetStringAsync("http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=100&tags="+ tag.Replace(" ", "_")).ConfigureAwait(false);
                var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
                if (matches.Count == 0)
                    return null;

                var rng = new NadekoRandom();
                var match = matches[rng.Next(0, matches.Count)];
                return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
            }
        }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:16,代码来源:NSFW.cs


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