我想知道如何将内容标题添加到 flurl 语句中。onedrive 实现要求我向内容添加内容类型标头,并尝试了所有可能的解决方案,但没有成功。
我被迫使用带有以下代码的常规 httpclient。
Public Async Function UploadFile(folder As String, filepath As String) As Task(Of Boolean) Implements ICloud.UploadFile
Dim data As Byte() = File.ReadAllBytes(filepath)
Dim uploadurl As String = "drive/items/" + folder + ":/" + Path.GetFileName(filepath) + ":/" + "content?access_token=" + Token.access_token
Using client As New HttpClient()
client.BaseAddress = New Uri(ApiUrl)
Dim request As HttpRequestMessage = New HttpRequestMessage(HttpMethod.Put, uploadurl)
request.Content = New ByteArrayContent(data)
request.Content.Headers.Add("Content-Type", "application/octet-stream")
request.Content.Headers.Add("Content-Length", data.Length)
Dim response = Await client.SendAsync(request)
Return response.IsSuccessStatusCode
End Using
End Function
我已经尝试过 Flurl 的常规 PutJsonAsync 方法,但没有运气。这是我的代码中剩下的唯一非 Flurl 部分。
提前谢谢。