Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTTP POST
#2
Now you can find C# code for tasks like this in stackoverflow and many other places on the internet. It is one of main advantages of QM3.

Script without trigger.
C# code:
// script "" //.
using Au; using Au.Types; using static Au.AStatic; using System; using System.Collections.Generic;
using System.Net;
using System.Text;
class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args) { //;;;

using (var client = new WebClient()) {
    client.Headers.Add("accept", "application/json");
    client.Headers.Add("content-type", "application/json-rpc");
    var enc = Convert.ToBase64String(Encoding.UTF8.GetBytes("admin:password"));
    client.Headers.Add("Authorization", $"Basic {enc}");
    var data = "{''jsonrpc'':''1.1'',''method'':''change'',''id'': 0,''params'':[{}]}";
    client.UploadString("http://192.168.1.1/test/", data);
}

}}

The same with the newer class HttpClient. May be slower. Both codes not tested.
C# code:
// script "" //.
using Au; using Au.Types; using static Au.AStatic; using System; using System.Collections.Generic;
using System.Net.Http;
using System.Text;
class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args) { //;;;

using var client = new HttpClient();
var h = client.DefaultRequestHeaders;
h.Add("accept", "application/json");
h.Add("content-type", "application/json-rpc");
var enc = Convert.ToBase64String(Encoding.UTF8.GetBytes("admin:password"));
h.Add("Authorization", $"Basic {enc}");
var data = "{''jsonrpc'':''1.1'',''method'':''change'',''id'': 0,''params'':[{}]}";
var r = client.PostAsync("http://192.168.1.1/test/", new StringContent(data)).Result;

}}


Messages In This Thread
HTTP POST - by redbull2k - 12-10-2019, 10:13 PM
RE: QM3 preview - by Gintaras - 12-10-2019, 10:53 PM
RE: QM3 preview - by redbull2k - 12-10-2019, 11:51 PM
RE: QM3 preview - by Gintaras - 12-11-2019, 12:03 AM
RE: QM3 preview - by redbull2k - 12-11-2019, 12:43 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)