• 大小: 223KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-04
  • 语言: C#
  • 标签: C#  .Net  Seafile  API  

资源简介

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


评论

共有 条评论