Skip to content

Commit 9bc542d

Browse files
http-package
1 parent 92c051c commit 9bc542d

File tree

8 files changed

+109
-67
lines changed

8 files changed

+109
-67
lines changed

HTTP/http.ezcode

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class http {
2+
method install : @str:url, @str:path {
3+
runexec http.dll.Http.HTTP.WebInstall ~> {url}, {path}
4+
}
5+
method GET : @str:url => @str {
6+
return runexec http.dll.Http.HTTP.GET ~> {url}
7+
}
8+
method POST : @str:url, @str:data, @str:contentType => @str {
9+
return runexec http.dll.Http.HTTP.GET ~> {url}, {data}, {contentType}
10+
}
11+
}

HTTP/http/Http.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using static EZCodeLanguage.EZHelp;
2+
using System.Net;
3+
using System.Text;
4+
5+
namespace Http
6+
{
7+
public class HTTP
8+
{
9+
public static void WebInstall(object _downloadUrl, object _downloadFilePath)
10+
{
11+
try
12+
{
13+
string brokenDownloadUrl = GetParameter<string>(_downloadUrl, typeof(string)),
14+
brokenRelativeDownloadFilePath = GetParameter<string>(_downloadFilePath, typeof(string));
15+
16+
string downloadUrl = FixUrlPath(brokenDownloadUrl),
17+
downloadRelativeFilePath = FixDirPath(brokenRelativeDownloadFilePath);
18+
19+
string fullFilePath = Path.GetFullPath(downloadRelativeFilePath);
20+
21+
WebClient webClient = new WebClient();
22+
webClient.DownloadFile(downloadUrl, fullFilePath);
23+
}
24+
catch (Exception ex)
25+
{
26+
throw ThrowError(ex);
27+
}
28+
}
29+
public static HttpClient HttpClient()
30+
{
31+
HttpClientHandler handler = new HttpClientHandler
32+
{
33+
AutomaticDecompression = DecompressionMethods.All
34+
};
35+
36+
return new HttpClient();
37+
}
38+
public static string GET(object _urlPath)
39+
{
40+
try
41+
{
42+
string brokenUrlPath = GetParameter<string>(_urlPath, typeof(string));
43+
string urlPath = FixUrlPath(brokenUrlPath);
44+
45+
return GetAsync(urlPath).Result;
46+
}
47+
catch (Exception ex)
48+
{
49+
throw ThrowError(ex);
50+
}
51+
}
52+
public static string POST(object _urlPath, string _data, string _contentType)
53+
{
54+
try
55+
{
56+
string brokenUrlPath = GetParameter<string>(_urlPath, typeof(string)),
57+
data = GetParameter<string>(_data, typeof(string)),
58+
contentType = GetParameter<string>(_contentType, typeof(string)),
59+
urlPath = FixUrlPath(brokenUrlPath);
60+
61+
return PostAsync(urlPath, data, contentType).Result;
62+
}
63+
catch (Exception ex)
64+
{
65+
throw ThrowError(ex);
66+
}
67+
}
68+
public static async Task<string> GetAsync(string uri)
69+
{
70+
using HttpResponseMessage response = await HttpClient().GetAsync(uri);
71+
72+
return await response.Content.ReadAsStringAsync();
73+
}
74+
public static async Task<string> PostAsync(string uri, string data, string contentType)
75+
{
76+
using HttpContent content = new StringContent(data, Encoding.UTF8, contentType);
77+
78+
HttpRequestMessage requestMessage = new HttpRequestMessage()
79+
{
80+
Content = content,
81+
Method = HttpMethod.Post,
82+
RequestUri = new Uri(uri)
83+
};
84+
85+
using HttpResponseMessage response = await HttpClient().SendAsync(requestMessage);
86+
87+
return await response.Content.ReadAsStringAsync();
88+
}
89+
}
90+
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<RootNamespace>io_package</RootNamespace>
65
<ImplicitUsings>enable</ImplicitUsings>
76
<Nullable>enable</Nullable>
87
</PropertyGroup>

IO/package.json renamed to HTTP/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"Name":"io",
2+
"Name":"http",
33
"Files": [
4-
"IO.ezcode"
4+
"http.ezcode"
55
],
66
"Configuration":{
7-
"LibraryDirectory":"io-package\\bin\\Debug\\net8.0\\",
7+
"LibraryDirectory":"http\\bin\\Debug\\net8.0\\",
88
"GlobalPackages":[
99
"main"
1010
]

IO/IO.ezcode

Lines changed: 0 additions & 11 deletions
This file was deleted.

IO/file-test.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

IO/io-package/IO.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

Main/Main.ezcode

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,11 @@ class file {
358358
method write : @str:path, @str:text => @str {
359359
return runexec EZCodeLanguage.EZHelp.FileWrite ~> {path}, {text}
360360
}
361-
method create : @str:path => @str {
362-
return runexec EZCodeLanguage.EZHelp.FileCreate ~> {path}
361+
method create : @str:path {
362+
runexec EZCodeLanguage.EZHelp.FileCreate ~> {path}
363+
}
364+
method delete : @str:path {
365+
runexec EZCodeLanguage.EZHelp.FileDelete ~> {path}
363366
}
364367
}
365368
global nocol method print : ! @str:__text {

0 commit comments

Comments
 (0)