从Windows IOT访问服务器Nancy,以c sharp开发 [英] Access Server Nancy from Windows IOT, develop in c sharp
问题描述
我们有这个代码来访问南希服务器:
We have this code to acces nancy server:
      试试
        {
            var url =" http://" + estacion +":2112 / estacion / iniciarjuego /" +  Juego;
            var webCliente = new WebClient();
            var content = webCliente.DownloadString(url);
$
            RespuestaData iepsData;
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RespuestaData));
            using(var ms = new MemoryStream(Encoding.Unicode.GetBytes(content)))
            {
                iepsData =(RespuestaData)serializer.ReadObject(ms);
            }
$
        }
        catch(例外情况)
        {
            // ErrorHandler.WriteEventLog(" Error al tratar de actualizar los IEPS:" + ex.Message);
        }
try
{
var url = "http://" + estacion + ":2112/estacion/iniciarjuego/" + Juego;
var webCliente = new WebClient();
var content = webCliente.DownloadString(url);
RespuestaData iepsData;
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RespuestaData));
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(content)))
{
iepsData = (RespuestaData)serializer.ReadObject(ms);
}
}
catch (Exception ex)
{
//ErrorHandler.WriteEventLog("Error al tratar de actualizar los IEPS: " + ex.Message);
}
这在windows中工作正常。
在Windows 10 io中,la class webclient不存在。
And this work fine in windows.
In Windows 10 io, la class webclient does not existe.
问题是:如何使用HttpClient或任何其他库创建此函数。
The question is: How to create this function using HttpClient or any other library.
推荐答案
你好,朋友
如上所述,UWP不支持webclient。但是,你可以使用HttpClient,请参考docs.microsoft.com上的这个文档,还有c#代码来演示如何使用HttpClient。祝你好运。
As you said above, webclient is not supported in UWP. However, you can use HttpClient instead, please refer to this doc on docs.microsoft.com, and there are also c# code there to demonstrate how to use HttpClient. Good luck.
1。
https://docs.microsoft.com/en-us/ uwp / api / Windows.Web.Http.HttpClient
2 。 https://docs.microsoft.com/en-us/windows/uwp/networking/httpclient
这篇关于从Windows IOT访问服务器Nancy,以c sharp开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!