Problem with basic access authentication in file downloader

前端 未结 1 2243
囚心锁ツ
囚心锁ツ 2021-02-20 10:43

I\'m having problems with downloading binary file (zip file) in my app from te internet. I have to use basic access authentication to authorize acces to file, but server respons

相关标签:
1条回答
  • 2021-02-20 11:00

    I might be a bit late but I just came across a similar problem. The problem lies in the following line:

    String encoding = Base64.encodeToString(authentication.getBytes(), 0);
    

    If you change that line to look like this it should work:

    String encoding = Base64.encodeToString(authentication.getBytes(), Base64.NO_WRAP);
    

    By default the Android Base64 util adds a newline character to the end of the encoded string. This invalidates the HTTP headers and causes the "Bad request".

    The Base64.NO_WRAP flag tells the util to create the encoded string without the newline character thus keeping the HTTP headers intact.

    0 讨论(0)
提交回复
热议问题