-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttps.cs
105 lines (102 loc) · 3.46 KB
/
Https.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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;
}
}
}
}