以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  请教web api的调用  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=87314)

--  作者:luodang2050
--  发布时间:2016/7/8 9:05:00
--  请教web api的调用

如下,为网盘下载文件的api,想集成代替ftp管理方案,在狐表应该怎么调用呢?请老师指个明路!

Download File

GET https://cloud.seafile.com/api2/repos/{repo-id}/file/?p=/foo

Request parameters

  • repo-id
  • p
  • reuse (optional): Set reuse to 1 if you want the generated download link can be accessed more than once in one hour.

Sample request

curl  -v  -H \'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd\' -H \'Accept: application/json; charset=utf-8; indent=4\' \'https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/file/?p=/foo.c&reuse=1\'

Sample response

"https://cloud.seafile.com:8082/files/adee6094/foo.c"

Errors

  • 400 Path is missing
  • 404 File not found
  • 520 Operation failed.

--  作者:大红袍
--  发布时间:2016/7/8 9:57:00
--  

 打不开你的链接。

 

 get、post请求参考

 

http://foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=73839&skin=0

 


--  作者:luodang2050
--  发布时间:2016/7/8 20:09:00
--  
以下这句是获取登录后的token值,已获取成功token:d5c3f6fa71a2d00254863528206cadd2c4c4e5f
curl -d "username=admin@seafile.com&password=admin" http://101.200.184.108/api2/auth-token/
以下为检测该token是否有效,该句参照上面的方法以及给的参考,怎么都获取不到,请帮忙分析下,谢谢
curl -H \'Authorization: Token d5c3f6fa71a2d00254863528206cadd2c4c4e5f\' http://101.200.184.108/api2/auth/ping/
测试代码:
Dim token As String = Functions.Execute("seafile_token")
Dim url0 As String = "http://101.200.184.108/"
Dim url As String = url0 & "api2/auth/ping"
Dim post As String
post="Authorization: Token " & token
Functions.Execute("post",url,post)
 
此主题相关图片如下:360反馈意见截图16620622818286.jpg
按此在新窗口浏览图片
相关函数:
\'Functions.Execute("seafile_token") \'获取token
Dim url0 As String = "http://101.200.184.108/"
Dim url As String = url0 & "api2/auth-token/"
Dim post As String = "username=admin@seafile.com&password=admin"
Dim txt As String = Functions.Execute("post",url,post)
txt=txt.SubString(11)
txt=txt.TrimEnd("}")
txt=txt.Trim("""")
MessageBox.Show("token:" & txt)
Return txt
 
\'函数调用0===================
\'Functions.Execute("post",url,post)
\'网页post提交并返回
\'函数调用1===================
Dim url As String = args(0)
Dim post As String = args(1)
Dim url0 As String = "http://101.200.184.108/"
Dim cookieheader As String =""
If args.length>2
    cookieheader= args(2)
End If
Dim msg As String = post
Dim req = System.Net.WebRequest.Create(url)
req.Method = "POST"
Dim cookieCon As new System.Net.CookieContainer()
req.CookieContainer = cookieCon
If cookieheader<>""
    req.CookieContainer.SetCookies(new Uri(url0), cookieheader)
End If
cookieheader= req.CookieContainer.GetCookieHeader(new Uri(url0))
msgbox(cookieheader )
req.C
Dim aryBuf As Byte() = Encoding.GetEncoding("GB2312").GetBytes(msg)
req.ContentLength = aryBuf.Length
Dim writer = req.GetRequestStream()
writer.Write(aryBuf, 0, aryBuf.Length)
writer.Close()
writer.Dispose()
Dim pos = req.GetResponse
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim str As String = reader.ReadToEnd
pos.Close
stm.Close
reader.close
Return str

[此贴子已经被作者于2016/7/8 20:15:34编辑过]

--  作者:luodang2050
--  发布时间:2016/7/9 8:29:00
--  
顶下别沉了
--  作者:Hyphen
--  发布时间:2016/7/9 9:46:00
--  
上传例子和接口完整说明
--  作者:luodang2050
--  发布时间:2016/7/9 13:36:00
--  

已上传实例,请在命令窗口直接调用函数“验证token”测试,谢谢!

API说明文档详见:http://manual.seafile.com/develop/web_api_v2.1.html

 

 下载信息  [文件大小:   下载次数: ]
点击浏览该文件:seafile文件管理测试.table

 

Quick Start

ping

curl https://cloud.seafile.com/api2/ping/

"pong"

obtain auth token

curl -d "username=username@example.com&password=123456" https://cloud.seafile.com/api2/auth-token/

{"token": "24fd3c026886e3121b2ca630805ed425c272cb96"}

auth ping

 

+

curl -H \'Authorization: Token 24fd3c026886e3121b2ca630805ed425c272cb96\' https://cloud.seafile.com/api2/auth/ping/

"pong"


 

[此贴子已经被作者于2016/7/9 13:36:59编辑过]

--  作者:Hyphen
--  发布时间:2016/7/9 14:40:00
--  
\'Functions.Execute("seafile_token") \'获取token
Dim url0 As String = "http://101.200.184.108/"
Dim url As String = url0 & "api2/auth-token/"
Dim post As String = "username=admin@seafile.com&password=admin"
Dim txt As String = Functions.Execute("post",url,post)
output.Show(txt)
txt=txt.SubString(10)
txt=txt.TrimEnd("}")
txt=txt.Trim("""")
output.Show("token:" & txt)
Return txt

--  作者:luodang2050
--  发布时间:2016/7/9 14:54:00
--  

图片点击可在新窗口打开查看原来是这么小的一个问题,参考了很多资料,以为调用方式有问题,折腾了很久,非常感谢。

真是好眼力图片点击可在新窗口打开查看


--  作者:Hyphen
--  发布时间:2016/7/9 15:21:00
--  
json最好解析成对象进行处理,用字符串分析容易出错
--  作者:luodang2050
--  发布时间:2016/7/10 9:56:00
--  
解析成对象是怎么解析了,能给个例子么?这方面刚接触,谢谢