我有一个项目,我有一个django服务器,它运行在一台机器上,用来与网络上的其他机器通信。
现在我在同一台机器上还有另一个用c编写的应用程序,用来监视某些硬件的状态。
我想知道是否有办法在c应用程序中编写http请求/响应系统,在那里我可以将它与django服务器接口,以便django向c应用程序发出请求时,它读取某些值并返回对django的响应。
有人能告诉我如何在c应用程序上编写这个http服务器吗?或者给我一些资源,我可以在那里查找。
谢谢
最佳答案
public string StoreEmail(string l_strEmail)
{
string l_strApiResponse = "";
try
{
using (var client = new HttpClient())
{
string l_strJson = "{'email':'" + l_strEmail + "'}";
var l_oJson = JObject.Parse(l_strJson);
client.BaseAddress = new Uri("http://170.0.0.0:8000/");
var response = client.PostAsJsonAsync("http://170.0.0.0:8000/user/testApi/", l_oJson).Result;
Task<string> responseString = response.Content.ReadAsStringAsync();
l_strApiResponse = responseString.Result;
}
}
catch (Exception ex)
{
}
return l_strApiResponse;
}
关于c# - Django与C#桌面应用程序的接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13107241/