HTTP POST request with authorization on android

前端 未结 2 1240
[愿得一人]
[愿得一人] 2020-12-07 21:57

When I set \"Authorization\" header with setHeader from HttpPost then hostname disappears from request and there is always error 400 (bad request) returned. Same code is wor

2条回答
  •  执笔经年
    2020-12-07 22:27

    use simply this :

    String authorizationString = "Basic " + Base64.encodeToString(
                            ("your_login" + ":" + "your_password").getBytes(),
                            Base64.NO_WRAP); //Base64.NO_WRAP flag
                    post.setHeader("Authorization", authorizationString);
    

提交回复
热议问题