Forum Discussion

DWade3's avatar
DWade3
Explorer | Level 3
5 years ago

405 method not allowed

I built file uploading application on c# using dropbox client, installed multiple devices and all working properly except one.  That one's error was:

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The remote server returned an error: (405) Method Not Allowed...

 

Is there might be Router block? or any suggestions? How do i solve?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    I'll be happy to help with any issues you're having with the Dropbox API, but I'll need some more information. Please reply with:

    • the name and version number of the platform and SDK/library you are using, if any
    • the steps to reproduce the issue, including relevant code snippet(s), but don't include the access token
    • DWade3's avatar
      DWade3
      Explorer | Level 3

      The library is Dropbox.API (Official Dropbox .Net v2 SDK, Runtime version: v4.0.30319). 

       

      Init code:

       

      var httpClient = new HttpClient(new WebRequestHandler { ReadWriteTimeout = 10 * 1000 })
                  {
                      Timeout = TimeSpan.FromMinutes(120)                
                  };
      
                  try
                  {
                      var config = new DropboxClientConfig("Smart Kontor")
                      {
                          HttpClient = httpClient
                      };
      
                      client = new DropboxClient(strAccessToken, config);
                  }
                  catch (HttpException ex)
                  {
                      MessageBox.Show("Exception reported from RPC layer");
                      MessageBox.Show("    Status code: " + ex.StatusCode);
                      MessageBox.Show("    Message    : " + ex.Message);
                  }

      Uploading code:

      try
                  {
                      var fileContent = File.ReadAllBytes(source_filepath);
      
                      using (var stream = new MemoryStream(fileContent))
                      {
                          file_size = (double)stream.Length;
                          int numChunks = (int)Math.Ceiling(file_size / chunkSize);
      
                          progressBarControl1.Properties.Maximum = numChunks;
      
                          byte[] buffer = new byte[chunkSize];
                          string sessionId = null;
      
                          for (var idx = 0; idx < numChunks; idx++)
                          {
                              var byteRead = stream.Read(buffer, 0, chunkSize);
                              
                              using (MemoryStream memStream = new MemoryStream(buffer, 0, byteRead))
                              {
                                  if (idx == 0)
                                  {
                                      var result = await client.Files.UploadSessionStartAsync(body: memStream);
                                      sessionId = result.SessionId;
                                  }
      
                                  else
                                  {
                                      UploadSessionCursor cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));
      
                                      if (idx == numChunks - 1)
                                      {
                                          await client.Files.UploadSessionFinishAsync(cursor, new CommitInfo(folder + "/" + fileName), memStream);
                                      }
                                      else
                                      {
                                          await client.Files.UploadSessionAppendV2Async(cursor, body: memStream);
                                      }
                                  }
                              }
      
                              progressBarControl1.PerformStep();
                          }
                      }

       

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        You seem to be setting some long timeout values, but other than that there doesn't seem to be anything unusual here. 

         

        Also, you didn't mention which version number of the Dropbox SDK itself you have, but I recommend upgrading to the latest version (currently v5.5.0), if you aren't already using that.

         

        Anyway, since there's nothing clearly wrong here, and since you mentioned this only happens on one device, it seems like there's something about that device in particular that is interfering. Is there anything on that device's network connection, such as a proxy, firewall, etc. that may be interfering with the connection? 

    • DWade3's avatar
      DWade3
      Explorer | Level 3

      I attached the code, please see below

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,949 PostsLatest Activity: 16 minutes ago
352 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!