C#在生产中使用Json Web服务
如何编写负责连接到restful api的库?lib应该提供直接访问api函数的方法。使用C#在生产中使用Json Web服务,c#,.net,json,C#,.net,Json,如何编写负责连接到restful api的库?lib应该提供直接访问api函数的方法。使用WebClient以字符串形式获取响应并Json.NET将它们反序列化为对象是否是一种可靠的、可接受的方法 ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;//the server uses a self signed SSL cert using (WebClient client = n
WebClient
以字符串形式获取响应并Json.NET
将它们反序列化为对象是否是一种可靠的、可接受的方法
ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;//the server uses a self signed SSL cert
using (WebClient client = new WebClient())
{
client.Headers.Add("..", "....");
string str = client.DownloadString("https://..../users/"+UserId+"/super-secret-data");
}
您可以为每组呼叫创建一个类(用户管理、启动/下载数据等)。此类实现了一些函数(映射web调用)。因此,当您想列出所有新成员时,您可以编写
var accounting = new Accounting();
var memberList = accounting.GetNewMember();
此函数(GetNewMember())只是一个包装器。在调用REST full API的函数中,获取JSON并将其转换为所需的结果
对于创建URI,您可以使用string.Format(string,object[])重载。您可以为每组调用创建一个类(用户管理,启动/下载数据,…)。此类实现了一些函数(映射web调用)。因此,当您想列出所有新成员时,您可以编写
var accounting = new Accounting();
var memberList = accounting.GetNewMember();
此函数(GetNewMember())只是一个包装器。在调用REST full API的函数中,获取JSON并将其转换为所需的结果
对于创建URI,您可以使用string.Format(string,object[])重载。您可以这样做,也可以使用visual studio和swagger的代码生成在解决方案中导入rest web api 您可以这样做,也可以使用visual studio和swagger的代码生成在解决方案中导入rest web api 谢谢,我已经使用了招摇过市,我不知道我可以使用它自动导入!很抱歉,我已经编写了整个Api连接器:汉克斯,我已经使用了招摇,我不知道我可以用它来自动导入!很抱歉,我已经编写了整个Api连接器:D