forked from MCCTeam/Minecraft-Console-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample-script-with-http-request.cs
34 lines (30 loc) · 1.21 KB
/
sample-script-with-http-request.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
//MCCScript 1.0
string mojangStatus = PerformHttpRequest("https://status.mojang.com/check");
MCC.LogToConsole(mojangStatus);
//MCCScript Extensions
string PerformHttpRequest(string uri)
{
var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
var response = (System.Net.HttpWebResponse)request.GetResponse();
string responseString;
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
responseString = reader.ReadToEnd();
return responseString;
}
void SendHttpPostAsync(string uri, string text)
{
new Thread(() => {
var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
request.ContentType = "text/plain";
request.Method = "POST";
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
streamWriter.Write(text);
var response = (System.Net.HttpWebResponse)request.GetResponse();
string responseString;
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
responseString = reader.ReadToEnd();
//LogToConsole(responseString);
}).Start();
}