BadScript 2
Loading...
Searching...
No Matches
BadNetApi.cs
Go to the documentation of this file.
2
7
11[BadInteropApi("Net")]
12internal partial class BadNetApi
13{
14 [BadMethod(description: "Encodes a URI Component")]
15 [return: BadReturn("The encoded URI Component")]
16 private string EncodeUriComponent([BadParameter(description: "The component to encode")] string s)
17 {
18 return Uri.EscapeDataString(s);
19 }
20
21 [BadMethod(description: "Decodes a URI Component")]
22 [return: BadReturn("The decoded URI Component")]
23 private string DecodeUriComponent([BadParameter(description: "The component to decode")] string s)
24 {
25 return Uri.UnescapeDataString(s);
26 }
27
28
35 [BadMethod(description: "Performs a POST request to the given url with the given content")]
36 [return: BadReturn("The Awaitable Task")]
37 private static BadTask Post(
38 [BadParameter(description: "The URL of the POST request")]
39 string url,
40 [BadParameter(description: "The String content of the post request")]
41 string content)
42 {
43 HttpClient cl = new HttpClient();
44
45 return new BadTask(
46 BadTaskUtils.WaitForTask(cl.PostAsync(url, new StringContent(content))),
47 $"Net.Post(\"{url}\")"
48 );
49 }
50
56 [BadMethod(description: "Performs a GET request to the given url")]
57 [return: BadReturn("The Awaitable Task")]
58 private static BadTask Get([BadParameter(description: "The URL of the GET request")] string url)
59 {
60 HttpClient cl = new HttpClient();
61 Task<HttpResponseMessage>? task = cl.GetAsync(url);
62
63 return new BadTask(BadTaskUtils.WaitForTask(task), $"Net.Get(\"{url}\")");
64 }
65}
Implements a Task Object.
Definition BadTask.cs:17
static BadInteropRunnable WaitForTask(System.Threading.Tasks.Task t)
Implements the "Net" Api.
Definition BadNetApi.cs:13
static BadTask Post([BadParameter(description:"The URL of the POST request")] string url, [BadParameter(description:"The String content of the post request")] string content)
Creates a new BadTask that performs a POST request to the given url with the given content.
Definition BadNetApi.cs:37
static BadTask Get([BadParameter(description:"The URL of the GET request")] string url)
Creates a new BadTask that performs a GET request to the given url.
Definition BadNetApi.cs:58
string DecodeUriComponent([BadParameter(description:"The component to decode")] string s)
Definition BadNetApi.cs:23
string EncodeUriComponent([BadParameter(description:"The component to encode")] string s)
Definition BadNetApi.cs:16
Contains task/async Extensions and Integrations for the BadScript2 Runtime.
Contains Networking Extensions and APIs for the BadScript2 Runtime.
Definition BadNetApi.cs:6