uTalk

Official forum for Utopia Community

You are not logged in.

#1 Re: Developer Thread » Utopia API + Node.js example » 2021-11-15 05:06:54

I will complete the topic by accessing the API with the .NET platform in the C # language. The console program displays the result of the getProfileStatus function (one of the APIs), based on which it is easy to implement others.

using System;
using System.Text;
using System.Net;

WebRequest request = WebRequest.Create("http://127.0.0.1:20001/api/1.0");
request.Method = "POST";
String mes1 = @"{""method"": ""getProfileStatus"", ""token"": ""7632261400226A4AEBF76EA4AD69CFC8""}";
Byte[] b = Encoding.UTF8.GetBytes(mes1);
string s = null;
Encoding enc8 = Encoding.UTF8;
s = enc8.GetString(b);
Console.WriteLine(s);
request.ContentLength = b.Length;
request.ContentType = "application/json; charset=utf-8";
Stream dataStream = request.GetRequestStream();
dataStream.Write(b, 0, b.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
using (dataStream = response.GetResponseStream())
{
    StreamReader reader = new StreamReader(dataStream);
    string str = reader.ReadToEnd();
    Console.WriteLine(str);
}
response.Close();
Console.ReadKey();

You just need to replace the port and token with your own. good luck writing programs!

Board footer

Powered by FluxBB