Foxtable(狐表)用户栏目专家坐堂 → 网盘api的post调用失败,请帮忙测试


  共有4827人关注过本帖树形打印复制链接

主题:网盘api的post调用失败,请帮忙测试

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/12 0:23:00 [显示全部帖子]

400错误,是服务器无法理解你的请求。你合成的post情况肯定有问题。

 

再有就是,你给的网址,都打不开。别人不知道怎么调用


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/12 10:16:00 [显示全部帖子]

 比如创建文件,就这样调用,其余的一样。

 

Dim msg As String = "operation=create"
Dim req = System.Net.WebRequest.Create("http://101.200.184.108/api2/repos/a716c6e0-23bf-450a-a7e7-b976c18f2ae9/file/?p=/foo.c")
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"    
req.Headers.Add("Authorization", "Token fd5c3f6fa71a2d00254863528206cadd2c4c4e5f")
req.Accept = "application/json; charset=utf-8; indent=4"

Dim aryBuf As Byte() = Encoding.GetEncoding("UTF-8").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
msgbox(str)

 

[此贴子已经被作者于2016/7/12 10:16:39编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/12 12:44:00 [显示全部帖子]

帮助文档有问题,要加上参数

 

Dim msg As String = "operation=copy&dst_repo=a716c6e0-23bf-450a-a7e7-b976c18f2ae9&dst_dir=/&file_names=foo.c"
Dim req = System.Net.WebRequest.Create("http://101.200.184.108/api2/repos/a716c6e0-23bf-450a-a7e7-b976c18f2ae9/file/?p=/foo.c")
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"    
req.Headers.Add("Authorization", "Token fd5c3f6fa71a2d00254863528206cadd2c4c4e5f")
req.Accept = "application/json; charset=utf-8; indent=4"
Dim aryBuf As Byte() = Encoding.GetEncoding("UTF-8").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
msgbox(str)

 

 

[此贴子已经被作者于2016/7/12 12:44:18编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/21 14:26:00 [显示全部帖子]

 不是这样吗?

 

req.Headers.Add("Authorization", "Token fd5c3f6fa71a2d00254863528206cadd2c4c4e5f")


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/21 16:39:00 [显示全部帖子]

 mark post上传文件

 

 看懂代码,你加入你对应的代码即可。

 

Dim file As String = "c:\test.txt"
Dim responseContent As String
Dim memStream As New IO.MemoryStream
Dim webRequest = System.Net.HttpWebRequest.Create("http://localhost:8080")
'边界符
Dim boundary As String = "---------------" + DateTime.Now.Ticks.ToString("x")
Dim beginBoundary As Byte() = Encoding.ASCII.GetBytes("--" & boundary & vbCrLf)
Dim endBoundary As Byte() = Encoding.ASCII.GetBytes(vbcrlf & "--" & boundary & "--" & vbcrlf)

Dim fileStream As new IO.FileStream(file, io.FileMode.Open, io.FileAccess.Read)

'设置属性
webRequest.Method = "POST"
webRequest.Timeout = 5000
webRequest.ContentType = "multipart/form-data; boundary=" & boundary

memStream.Write(beginBoundary, 0, beginBoundary.Length)

'写入文件1
Dim header As String = "Content-Disposition: form-data; name=""file"";filename=""" & FileIO.FileSystem.GetName(file) & """" & vbCrLf & "Content-Type: application/octet-stream" & vbCrLf & vbCrLf
Dim headerbytes As Byte() = Encoding.UTF8.GetBytes(header)
memStream.Write(headerbytes, 0, headerbytes.Length)

Dim buffer(1024) As Byte
Dim bytesRead As Integer = fileStream.Read(buffer, 0, buffer.Length)
While bytesRead > 0
    memStream.Write(buffer, 0, bytesRead)
    bytesRead = fileStream.Read(buffer, 0, buffer.Length)
End While

'写入最后的结束边界符
memStream.Write(endBoundary, 0, endBoundary.Length)
webRequest.ContentLength = memStream.Length

Dim requestStream = webRequest.GetRequestStream

memStream.Position = 0
Dim tempBuffer(memStream.Length - 1) As Byte
memStream.Read(tempBuffer, 0, tempBuffer.Length)
memStream.Close()

requestStream.Write(tempBuffer, 0, tempBuffer.Length)
requestStream.Close()
msgbox(5)
Dim httpWebResponse As Net.WebResponse = webRequest.GetResponse
msgbox(6)
Dim httpStreamReader As new Io.StreamReader(httpWebResponse.GetResponseStream, Encoding.GetEncoding("utf-8"))
responseContent = httpStreamReader.ReadToEnd

fileStream.Close()
httpWebResponse.Close()
webRequest.Abort()

msgbox( responseContent)

[此贴子已经被作者于2016/7/21 16:39:39编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/21 17:43:00 [显示全部帖子]

1、你的的调用地址有问题。

 

2、直接去问人家给你一个c#的例子不是更好?去找弄好的实例。


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/22 12:38:00 [显示全部帖子]

 做好的话,发代码看看怎么处理的。

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/24 15:50:00 [显示全部帖子]

谢谢分享。

 回到顶部