Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pass optional parameters as params
#1
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.
 
Code:
Copy      Help
//.
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
Code:
Copy      Help
// 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;
    }
}
#2
That HTTP server code does not support params and arrays. The supported parameter types are documented in the code, below the HttpSession class.
#3
Thanks for your help.
Is there a way to implement it(params)? Also, the function have an overload test2(string t)
#4
No.
Overloads not supported.
#5
Arrays with any number of elements can be passed using JSON. The new HTTP server code makes it easier.
 
Code:
Copy      Help
// 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);
        }
    }
}
#6
Why can't the following code exist simultaneously?
https://i.ibb.co/9yzGyJX/AAA.gif

Code:
Copy      Help
// 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" }));
#7
record R1(int i, string s); is a type definition, it must be at the end.
#8
Thank you!
passing parameters through JSON is very convenient now.


Forum Jump:


Users browsing this thread: 1 Guest(s)