0

First of all I would like to apologize but this is the first time I use these tools (HttpClient and SendAsync ) I'd like to download asynchronously a file ( video / image / text ) from dropbox by the call files/download. This is my code but when the excecution arrive in the line with SendAsync the program exit from the function. Is there an error? how can I find it?

 Async Function Download_Async(ByVal _file As String) As Task Dim client As HttpClient = New HttpClient() Dim _Request As HttpRequestMessage = New HttpRequestMessage(HttpMethod.Post, "https://content.dropboxapi.com/2/files/download") _Request.Headers.Add("Authorization", "Bearer " + _token) _Request.Headers.Add("Dropbox-API-Arg", _path_file) Dim _message = Await client.SendAsync(_Request) Dim res = Await _message.Content.ReadAsStringAsync() 

I installed last version of nuget package System.Net.Http 4.3.4. and i try to change in various mode the define of HttpRequestMessage and SendAsync but this is ( i think ) the correct way.

I changed the firsts line

 Dim client As New HttpClient Dim _Request = New HttpRequestMessage(Http.HttpMethod.Post, "https://content.dropboxapi.com/2/files/download") 

Error is : "Object reference not set to an instance of an object"

7
  • It would be great to know what does the error message say or at least what sort of exception is thrown. Commented Aug 30, 2024 at 8:10
  • The error is "Object reference not set to an instance of an object Commented Aug 30, 2024 at 10:46
  • Thank you. From the stack trace could you please share with us which line is throwing this NullReferenceException? Commented Aug 30, 2024 at 11:10
  • Dim _message = Await client.SendAsync(_Request) Commented Aug 30, 2024 at 12:22
  • That means either the client or the _Request could be null. Could you please update the question with the entire stacktrace? Commented Sep 2, 2024 at 9:09

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.