You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.3 KiB

using Flurl;
using Flurl.Http;
using Newtonsoft.Json.Linq;
using System;
3 years ago
using System.Net.Http;
3 years ago
namespace OnvifSocketServer
{
public class Program
3 years ago
{
public static void Main(string[] args)
3 years ago
{
Console.WriteLine("Hello World!");
3 years ago
TestOnvifUrl();
Console.ReadLine();
}
3 years ago
public static void TestOnvifUrl()
{
string onvifHttpUrl = AppConfig.GetOnvifHttpUrl();
string onvifHttpsUrl = AppConfig.GetOnvifHttpsUrl();
3 years ago
Uri baseUri = new Uri(onvifHttpUrl);
JObject result;
Console.WriteLine(onvifHttpUrl);
// Get
result = baseUri.AbsoluteUri
.AppendPathSegment("onvif/Curd/IsExist")
.SetQueryParams(new { ip = "192.168.1.108" })
.GetAsync()
.ReceiveJson<JObject>().Result;
Console.WriteLine(result);
// Post
result = baseUri.AbsoluteUri
.AppendPathSegment("onvif/Curd/Add")
.SetQueryParams(new { ip = "192.168.1.65", username = "admin", password = "hk123456" })
.PostAsync()
.ReceiveJson<JObject>().Result;
Console.WriteLine(result);
result = Request(baseUri, "onvif/Media/GetStreamUri", HttpMethod.Get, new { ip = "192.168.1.65" });
result = Request(baseUri, "onvif/Media/GetSnapshotUri", HttpMethod.Get, new { ip = "192.168.1.65" });
// Post
result = Request(baseUri, "onvif/Curd/Add", HttpMethod.Post,
new { ip = "192.168.1.108", username = "admin", password = "hk123456" });
result = Request(baseUri, "onvif/Media/GetStreamUri", HttpMethod.Get, new { ip = "192.168.1.108" });
result = Request(baseUri, "onvif/Media/GetSnapshotUri", HttpMethod.Get, new { ip = "192.168.1.108" });
}
public static JObject Request(Uri uri, string relativePath, HttpMethod httpMethod, object data)
{
Url url = uri.AbsoluteUri.AppendPathSegment(relativePath).SetQueryParams(data);
JObject result;
if (httpMethod == HttpMethod.Get)
{
result = url.GetAsync().ReceiveJson<JObject>().Result;
}
else if (httpMethod == HttpMethod.Post)
{
result = url.PostAsync().ReceiveJson<JObject>().Result;
}
else if (httpMethod == HttpMethod.Put)
{
result = url.PutAsync().ReceiveJson<JObject>().Result; ;
}
else if (httpMethod == HttpMethod.Delete)
{
result = url.DeleteAsync().ReceiveJson<JObject>().Result; ;
}
else
{
result = null;
}
Console.WriteLine(result);
3 years ago
return result;
3 years ago
}
}
}