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;
using System.Net.Http;
namespace OnvifSocketServer
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
TestOnvifUrl();
Console.ReadLine();
}
public static void TestOnvifUrl()
{
string onvifHttpUrl = AppConfig.GetOnvifHttpUrl();
string onvifHttpsUrl = AppConfig.GetOnvifHttpsUrl();
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);
return result;
}
}
}