Posts: 1,049
Threads: 249
Joined: Jul 2022
05-05-2024, 09:47 PM
(This post was last modified: 05-05-2024, 10:32 PM by Davider.)
I'm using the following code to send HTTP requests, but always get the following error:
StatusCode: 400, ReasonPhrase: 'BadRequest', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Sun, 05 May 2024 21:45:56 GMT
Server: Au
Content-Type: text/plain; charset=utf-8
Content-Length: 27
}
The args parameter can have zero or more arguments. In the following example, there are zero arguments.
//.
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.Pause);
//..
string s="hello";
string r = internet.http.Get($"http://localhost:4455/test2?t={s}").Text();
print.it(r);
Use HTTP server:
https://www.quickmacros.com/forum/showth...6#pid36746
// class "Function2.cs"
static partial class Functions
{
public static string test2(string t, params object[] args)
{
print.it(args.Length);
return t;
}
public static string test2(string t)
{
return t;
}
}
Posts: 12,095
Threads: 142
Joined: Dec 2002
05-06-2024, 03:33 AM
(This post was last modified: 05-06-2024, 03:58 AM by Gintaras.)
That HTTP server code does not support params and arrays. The supported parameter types are documented in the code, below the HttpSession class.
Posts: 1,049
Threads: 249
Joined: Jul 2022
05-06-2024, 05:16 AM
(This post was last modified: 05-06-2024, 05:17 AM by Davider.)
Thanks for your help.
Is there a way to implement it(params)? Also, the function have an overload test2(string t)
Posts: 12,095
Threads: 142
Joined: Dec 2002
No.
Overloads not supported.
Posts: 12,095
Threads: 142
Joined: Dec 2002
05-06-2024, 07:54 AM
(This post was last modified: 05-06-2024, 08:21 AM by Gintaras.)
Arrays with any number of elements can be passed using JSON. The new HTTP server code makes it easier.
// class "HTTP server Functions test.cs"
using System.Text.Json.Nodes;
static partial class Functions {
//client example: LaHttp.CallJ("TestJsonArray", new string[] { "a", "b" });
//client example without LaHttp: internet.http.Post("http://localhost:4455/TestJsonArray", internet.jsonContent(new string[] { "a", "b" }));
public static void TestJsonArray(string[] a) {
foreach (string v in a) {
print.it(v);
}
}
}
Posts: 1,049
Threads: 249
Joined: Jul 2022
Why can't the following code exist simultaneously?
https://i.ibb.co/9yzGyJX/AAA.gif
// script "LaHttp Run _T2.cs"
/*/ c LaHttp.cs; /*/ //.
using System.Text.Json;
using System.Text.Json.Nodes;
//..
// 6
internet.http.Post("http://localhost:4455/JsonSimple", internet.jsonContent(new R1(5, "text"))); record R1(int i, string s);
//internet.http.Post("http://localhost:4455/JsonSimple", internet.jsonContent(new { i = 5, s = "text" }));
// 7
//Arrays with any number of elements can be passed using JSON. The new HTTP server code makes it easier.
//LaHttp.CallJ("TestJsonArray", new string[] { "a", "b" });
internet.http.Post("http://localhost:4455/TestJsonArray", internet.jsonContent(new string[] { "a", "b" }));
Posts: 12,095
Threads: 142
Joined: Dec 2002
record R1(int i, string s); is a type definition, it must be at the end.
Posts: 1,049
Threads: 249
Joined: Jul 2022
Thank you!
passing parameters through JSON is very convenient now.