资源简介
seafile私有云的api的C#客户端实现

代码片段和文件信息
using Microsoft.Http;
using Microsoft.Http.Headers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
namespace WCFRestFulClient4
{
class ClientHelper
{
private readonly static string baseUrl = “api的网址“;
private readonly static User objUser = new User { username = ““ password = ““ };
private readonly static Token objToken = new Token { token = ““ };
private readonly static string TWO_HYPENS = “--“;
private readonly static string BOUNDARY = “----haining“;
private readonly static string CRLF = “\r\n“;
private static HttpContent GetContent(T task)
{
var strContent = JsonConvert.Serializeobject(task);
var data = System.Text.Encoding.UTF8.GetBytes(strContent);
return HttpContent.Create(data “application/json“);
}
//ping
public static void PingApi()
{
var client = new HttpClient();
var strUrl = baseUrl + “ping/“;
var response = client.Get(strUrl);
response.EnsureStatusIsSuccessful();
var json = response.Content.ReadAsString();
Console.WriteLine(json);
}
//obtain auth token
public static void GetToken()
{
var client = new HttpClient();
var strUrl = baseUrl + “auth-token/“;
Token token = new Token();
HttpMultipartMimeForm fs = new HttpMultipartMimeForm();
fs.Add(“username“ ““);
fs.Add(“password“ ““);
var response = client.Post(strUrl fs.CreateHttpContent());//GetContent(objUser));
response.EnsureStatusIsSuccessful();
var json = response.Content.ReadAsString();
var data = JsonConvert.Deserializeobject>(json);
Console.WriteLine(data[“token“]);
}
//auth ping
public static void AuthPingApi()
{
var client = new HttpClient();
var strUrl = baseUrl + “auth/ping/“;
RequestHeaders head = new RequestHeaders();
head.Add(“Authorization“ “Token “ + objToken.token);
client.DefaultHeaders = head;
var response = client.Get(strUrl);
response.EnsureStatusIsSuccessful();
var json = response.Content.ReadAsString();
Console.WriteLine(json);
}
//list accounts
public static void ListAccounts()
{
var client = new HttpClient();
var strUrl = baseUrl + “auth-token/“;
RequestHeaders head = new RequestHeaders();
head.Add(“Authorization“ “Token “ + objToken.token);
head.Add(“Accept“ “application/json;indent=4“);
var
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 15259 2014-06-18 17:28 WCFRestFulClient_for_seafile\ClientHelper.cs
文件 119648 2009-12-10 09:38 WCFRestFulClient_for_seafile\Lib\Microsoft.Http.dll
文件 28536 2009-12-10 09:38 WCFRestFulClient_for_seafile\Lib\Microsoft.Http.Extensions.dll
文件 117112 2009-12-10 09:38 WCFRestFulClient_for_seafile\Lib\Microsoft.ServiceModel.Web.dll
文件 319488 2013-09-15 03:00 WCFRestFulClient_for_seafile\Lib\Newtonsoft.Json.dll
文件 1149 2014-03-11 15:49 WCFRestFulClient_for_seafile\Program.cs
文件 1414 2014-02-14 10:48 WCFRestFulClient_for_seafile\Properties\AssemblyInfo.cs
文件 590 2014-02-20 16:23 WCFRestFulClient_for_seafile\User.cs
文件 3133 2014-02-17 12:12 WCFRestFulClient_for_seafile\WCFRestFulClient4.csproj
文件 1603 2014-02-14 17:04 WCFRestFulClient_for_seafile\WCFRestFulClient4.sln
..A..H. 19456 2014-06-18 17:28 WCFRestFulClient_for_seafile\WCFRestFulClient4.suo
..A..H. 36352 2013-12-04 21:40 WCFRestFulClient_for_seafile\WCFRestFulClient4.v12.suo
目录 0 2013-12-04 20:55 WCFRestFulClient_for_seafile\Lib
目录 0 2014-02-21 16:07 WCFRestFulClient_for_seafile\Properties
目录 0 2014-02-21 16:07 WCFRestFulClient_for_seafile
----------- --------- ---------- ----- ----
663740 15
- 上一篇:c#窗体嵌入应用程序
- 下一篇:C#+AE根据点坐标生成shp文件
相关资源
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- Asp.net学生信息管理系统源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- ASP.NET实验室预约管理系统
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 020ASP.NET车辆综合管理系统.zip
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
评论
共有 条评论