JAVA中的授权头字符长度有限制吗?

JAVA中的授权头字符长度有限制吗?,java,android,http-headers,authorization,Java,Android,Http Headers,Authorization,我正在从android应用程序发送GET请求,包括授权标题。 当我在服务器上检查auth.password时,它将被截断。 原始字符串为60个字符,服务器仅接收48个字符。 密码是一个哈希字符串 下面是生成请求的函数的代码 private String getToken(username, password){ InputStream inputStream = null; String result = ""; try {

我正在从android应用程序发送GET请求,包括授权标题。 当我在服务器上检查auth.password时,它将被截断。 原始字符串为60个字符,服务器仅接收48个字符。 密码是一个哈希字符串

下面是生成请求的函数的代码

private String getToken(username, password){
        InputStream inputStream = null;
        String result = "";
        try {

            // create HttpClient

            HttpClient httpclient = new DefaultHttpClient();

            HttpGet httpGet= new HttpGet(url);

            String credentials= "";
            if (username.length != 0 && password.length != 0) ){
                credentials= username + ":"+ password
            }else {
                return "";
            }

            String encoding= Base64.encodeToString(credentials.getBytes("utf-8"),Base64.DEFAULT);
            httpGet.setHeader(HttpHeaders.HOST,SERVER);
            httpGet.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + encoding);

            // make GET request to the given URL
            HttpResponse httpResponse = httpclient.execute(httpGet);

            // receive response as inputStream
            inputStream = httpResponse.getEntity().getContent();

            // convert inputstream to string
            if(inputStream != null) {
                result = convertInputStreamToString(inputStream);

                result = new JSONObject(result).getString("token");
            }


        } catch (Exception e) {
            Log.d("InputStream", e.getLocalizedMessage());
            result= "";
        }

        return result;

    }
            
将变量编码解码回字符串将为我提供原始凭证
Log.e(标记“getToken:DECODED BYTES”+新字符串(Base64.decode(encoding,0),“utf-8”)

从邮递员发送相同的请求不会截断密码

密码示例
$2b$12$FywsqVzLrCR1iSVDLe7eBeK/.K07JUXX9YEHklyWPz9W7/nj52Xfa


服务器应用程序是用python编写的,所以答案是更改这行代码
String encoding=Base64.encodeToString(credentials.getBytes(“utf-8”)、Base64.DEFAULT)

String encoding=Base64.encodeToString(credentials.getBytes(“utf-8”)、Base64.URL_SAFE | Base64.NO_WRAP)

这将保护url不受之类字符的影响(点),尤指加密密码。
如果您检查示例密码,就会看到点字符。

您是否介意将JAVA版本添加到您的问题中?另外,请求?JAVA版本>>openjdk版本“1.8.0_202-release”中所有头的总大小。我不知道该怎么做,但是我的请求没有任何其他头,除了默认的+授权头gotcha。因为postman+JAVA似乎为您做了正确的事情,但是android+JAVA没有。。。我怀疑问题不在于JAVA端点,而在于android应用程序发送的内容。你能发布一些代码吗?或者你的问题已经是这样了?