百度官方的确没有给出直接使用用户名和密码进行登录的api,但这倒不是无解,就是稍微有点繁琐,上面回复你了:github上搜一下:https://passport.baidu.com/v2/api/?login
参照代码思路搬运一下。
再比如搜索baidu oauth passport.baidu.com也行
得到的这个,基本就是完整代码了:https://github.com/qhgz2013/BaiduCloudSync/blob/master/BaiduCloudSync/api/baidu-oauth.cs
不想写这些代码的话,可以跳过百度网盘,使用其他方式备份(FTP或者WebDav),有点答非所问了,上面百度的懒得写到foxtable主要是因为百度登录不开放,一是登录地址和登录方法估计会时不时变化,二是会可能出现要输入验证码的情况,懒得搞了
这是我写的Foxtable示例代码,上传文件到坚果云。免费版每月1GB的上传流量。这个云盘挺不错的,还有增量备份和文件历史记录快照的功能。
国内网盘只有坚果云和诚通网盘支持WebDav,诚通的禁止通过WebDav下载,免费用户网页下载限速,但优点是容量有500GB。
不喜欢可以用国外的网盘,或者自己搭建网盘,比如群辉再开启WebDav Server就行了
'参考来源:https://github.com/ZZRRegion/JianGuoYunWebDav/blob/master/JianGuoYunWebDav/HttpWebDav.cs
'!!!注意需要添加.Net原生的System.Net.Http.dll外部引用!!!
'坚果云开启WebDav方法:https://help.jianguoyun.com/?p=2064
'配置坚果云的账号、密码、webdav地址、要上传的文件
Dim UserName As String = "xxx@xxx.com"
Dim Password As String = "xxx"
'必须上传到我的坚果云文件夹下,否则会提示404。
Dim BaseUrl As String = "https://dav.jianguoyun.com/dav/我的坚果云/"
Dim file As String = "D:\已检验未入库.xls"
'初始化Http客户端
Dim httpClientHandler As New System.Net.Http.HttpClientHandler()
httpClientHandler.UseProxy = True
httpClientHandler.Proxy = New System.Net.WebProxy()
httpClientHandler.Credentials = New System.Net.NetworkCredential(UserName, Password)
httpClientHandler.PreAuthenticate = True
Dim httpClient As New System.Net.Http.HttpClient(httpClientHandler)
'读取文件并上传
Dim finfo As New System.IO.FileInfo(file)
'如果已存在同名文件且内容有变化,将会被覆盖并自动保留历史版本。
Dim url As String = BaseUrl + finfo.Name
Dim byteArrayContent As New System.Net.Http.ByteArrayContent(System.IO.File.ReadAllBytes(file))
'发送http请求
Dim clientTask = httpClient.PutAsync(url, byteArrayContent)
'等待请求结果
clientTask.Wait()
Dim rep As System.Net.Http.HttpResponseMessage = clientTask.Result
If rep.IsSuccessStatusCode Then
Output.Show("文件上传成功!")
Else
Output.Show("文件上传失败:" & rep.StatusCode)
End If
''创建文件夹
' Dim fdname As String = "测试文件夹"
' Dim httpRequestMessage As New System.Net.Http.HttpRequestMessage()
' httpRequestMessage.Method = New System.Net.Http.HttpMethod("MKCOL")
' httpRequestMessage.RequestUri = New Uri(BaseUrl + fdname)
' clientTask = httpClient.SendAsync(httpRequestMessage)
' clientTask.Wait()
' If clientTask.Result.IsSuccessStatusCode Then
' Output.Show("文件夹创建成功!")
' Else
' Output.Show("文件夹创建失败:" & clientTask.Result.StatusCode)
' End If
' '删除文件
' Dim deleteFile As String = "测试删除文件.btw"
' httpRequestMessage = New System.Net.Http.HttpRequestMessage()
' httpRequestMessage.Method = System.Net.Http.HttpMethod.Delete
' httpRequestMessage.RequestUri = New Uri(BaseUrl + deleteFile)
' clientTask = httpClient.SendAsync(httpRequestMessage)
' clientTask.Wait()
' If clientTask.Result.IsSuccessStatusCode Then
' Output.Show("文件删除成功!")
' Else
' Output.Show("文件删除失败:" & clientTask.Result.StatusCode)
' End If
' '下载文件
' Dim downFile As String = "【01】坚果云快速向导.pdf"
' Dim downPath As String = "D:\"
' url = BaseUrl + downFile
' Dim task = httpClient.GetByteArrayAsync(url)
' task.Wait()
' If task.IsCompleted Then
' System.IO.File.WriteAllBytes(downPath + downFile, task.Result)
' Output.Show("文件下载成功!")
' else
' Output.Show("文件下载失败!")
' End If
[此贴子已经被作者于2022/12/31 13:42:59编辑过]