1 Star 0 Fork 82

yinsitan/BBBUG Windows Client

forked from BBBUG/BBBUG Windows Client 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Https.cs 3.46 KB
一键复制 编辑 原始数据 按行查看 历史
Hamm 提交于 2020-10-21 17:20 . add: 添加了一些功能
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace BBBUG {
public static class Https
{
public static string CodeSuccess = "200";
public static string CodeForbbiden = "403";
public static string CodeLogin = "401";
public static string CodeRedirectForce = "301";
public static string CodeRedirect = "302";
public static string CodeError = "500";
public static string BaseApiUrl = "https://api.bbbug.com/api/";
public static string AccessToken = "";
public static string Plat = "windows app";
public static string Version = "10000";
public static async Task<JObject> PostAsync(string url, Dictionary<string, string> postDict)
{
if (!postDict.ContainsKey("access_token"))
{
postDict.Add("access_token", Https.AccessToken);
}
else
{
postDict["access_token"] = Https.AccessToken;
}
if (!postDict.ContainsKey("plat"))
{
postDict.Add("plat", Https.Plat);
}
else
{
postDict["plat"] = Https.Plat;
}
if (!postDict.ContainsKey("version"))
{
postDict.Add("version", Https.Version);
}
else
{
postDict["version"] = Https.Version;
}
var postData = new FormUrlEncodedContent(postDict);
Console.WriteLine(postData.ToString());
var handler = new HttpClientHandler()
{
AutomaticDecompression = DecompressionMethods.GZip
};
using (var http = new HttpClient(handler))
{
var response = await http.PostAsync(Https.BaseApiUrl + url, postData);
string data = await response.Content.ReadAsStringAsync();
return (JObject)JsonConvert.DeserializeObject(data);
}
}
public static async Task<HttpResponseMessage> PostMusicUrl(string url, Dictionary<string, string> postDict)
{
if (!postDict.ContainsKey("access_token"))
{
postDict.Add("access_token", Https.AccessToken);
}
else
{
postDict["access_token"] = Https.AccessToken;
}
if (!postDict.ContainsKey("plat"))
{
postDict.Add("plat", Https.Plat);
}
else
{
postDict["plat"] = Https.Plat;
}
if (!postDict.ContainsKey("version"))
{
postDict.Add("version", Https.Version);
}
else
{
postDict["version"] = Https.Version;
}
var postData = new FormUrlEncodedContent(postDict);
Console.WriteLine(postData.ToString());
var handler = new HttpClientHandler()
{
AutomaticDecompression = DecompressionMethods.GZip,
AllowAutoRedirect=false
};
using (var http = new HttpClient(handler))
{
var response = await http.PostAsync(Https.BaseApiUrl + url, postData);
return response;
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/yinsitan/BBbug_Winform_Applicaiton.git
git@gitee.com:yinsitan/BBbug_Winform_Applicaiton.git
yinsitan
BBbug_Winform_Applicaiton
BBBUG Windows Client
master

搜索帮助