|
-
Aug 15th, 2024, 09:43 AM
#1
Thread Starter
New Member
Access dropbox file - The remote server returned an error: (404) Not Found
i'm new in this type of access.
I wrote this code but i have the error in objet to recover the list of files in dropbox.
Code:
Dim token As String
token = "sl.B6........."
Dim _command As String
_command = "https://api.dropboxapi.com/2/files/list_folder"
Dim Request As HttpWebRequest
Request = HttpWebRequest.Create(_command)
Request.Method = "GET"
Request.KeepAlive = True
Request.ContentType = "application/x-www-form-urlencoded"
Request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
Request.AllowAutoRedirect = True
Request.Headers.Add("Authorization", "Bearer " & token)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim Response As HttpWebResponse = Request.GetResponse()
Last edited by dday9; Aug 15th, 2024 at 09:46 AM.
-
Aug 15th, 2024, 09:54 AM
#2
Re: Access dropbox file - The remote server returned an error: (404) Not Found
404 typically means that it cannot find the file you're requesting.
It looks like you're hitting the files/list_folder endpoint (documentation). To be honest, I'm a bit surprised you're getting a 404.
But looking at the documentation it looks like you've setup your headers incorrectly. The ContentType should be application/json. I don't think that's the underlying issue, but it's worth changing nonetheless.
-
Aug 15th, 2024, 11:33 AM
#3
Thread Starter
New Member
Re: Access dropbox file - The remote server returned an error: (404) Not Found
ty.
I changed it and now the error is ::
Authentication failed because the remote party has closed the transport stream.
i try to change this ...
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
with or without i have the same error.
Last edited by Lukager1; Aug 15th, 2024 at 11:40 AM.
-
Aug 15th, 2024, 11:55 AM
#4
Re: Access dropbox file - The remote server returned an error: (404) Not Found
That does suggest a security issue. Try moving the call further up in your code and additionally specify more options:
Code:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls
-
Aug 15th, 2024, 12:22 PM
#5
Thread Starter
New Member
Re: Access dropbox file - The remote server returned an error: (404) Not Found
i moved it
Request.Method = "GET"
Request.KeepAlive = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls
Request.ContentType = "application/json"
and i have the error :
Message=Remote server error: (404) Not found.
is it correct that i have all the path in the variable _command ?
or i must set the server in another place and there just the final path (/files/list_folder) ?
-
Aug 15th, 2024, 01:14 PM
#6
Re: Access dropbox file - The remote server returned an error: (404) Not Found
The only other thing I can think of is that you're not including any kind of path parameter in your request. The other parameters appear to either be optional or have default values.
Actually, come to think of it, you should be sending a POST command instead of a GET as well. Try changing the method first, if that doesn't work on its own then also try adding a payload with a "path" property and value:
Code:
Private Function DropBoxListFolder()
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls
Dim url = "https://api.dropboxapi.com/2/files/list_folder"
Dim token = "..."
Dim request = CType(WebRequest.Create(url), HttpWebRequest)
request.Method = "POST"
request.Headers.Add("Authorization", $"Bearer {token}")
request.ContentType = "application/json"
Dim payloadLiteral = "{
""path"": ""-change me-""
}"
Dim payload = Encoding.UTF8.GetBytes(payloadLiteral)
request.ContentLength = payload.Length
Using dataStream = request.GetRequestStream()
dataStream.Write(payload, 0, payload.Length)
End Using
Try
Using response = CType(request.GetResponse(), HttpWebResponse)
Using reader = New StreamReader(response.GetResponseStream())
Return reader.ReadToEnd()
End Using
End Using
Catch ex As WebException
Using response = CType(ex.Response, HttpWebResponse)
Using reader = New StreamReader(response.GetResponseStream())
Throw New Exception(reader.ReadToEnd())
End Using
End Using
Catch ex As Exception
Throw
End Try
End Sub
-
Aug 15th, 2024, 01:48 PM
#7
Thread Starter
New Member
Re: Access dropbox file - The remote server returned an error: (404) Not Found
changing just the POST i have an error 401 not authorized
If i try to change the code with yours it's the same.
I try with
Dim payloadLiteral = "{""path"": ""https://www.dropboxapi.com""}"
or
Dim payloadLiteral = "{""path"": ""https://api.dropboxapi.com""}"
and the error it is the some
-
Aug 15th, 2024, 01:57 PM
#8
Re: Access dropbox file - The remote server returned an error: (404) Not Found
401 typically means that your authentication is not setup properly, you need to double-check that.
Regarding your path, you should not be setting it to DropBox rather the path you want to search (if applicable).
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|