如何在循环中调用 httpconeection setRequestProperty android 到 setHeader?

how to call httpconeection setRequestProperty android in loop to setHeader?

HTTPConnection 连接 方法

setRequestProperty

conn.setRequestProperty("","");

不同的URL我有不同的header。所以,它在我的项目中没有修复。 我需要用数组来填充setRequestproperty数据。

单独调用 setRequestProperty 它正在工作 1stPart .

我试图将相同的内容调用到数组中,但它不起作用“第 2 部分”。

1) conn.setRequestProperty("Authorization","12345678");
  conn.setRequestProperty("ReToken", "erjeorjeorjeoureorjr");


2)  

String[] array1 = new String[]{"Authorization","12345678","RefreshToken","erjeorjeorjeoureorjr"};`

                if (array1 != null) {
                    int size = array1.length;

                    for (int i = 0; i < size; i = i + 2) {
                        conn.setRequestProperty('"' + array1[i] + '"',
                                '"' + array1[i + 1] + '"');
                         Log.d(TAG,"Value Print:: " + array1[i] + " ," + 
                                 array1[i+1] );
                    }
                }

您正在尝试将已经是字符串的内容转换为字符串。只需删除数组周围的双引号。 试试这个:

for (int i = 0; i < size; i = i + 2) {
    conn.setRequestProperty(array1[i] ,array1[i + 1]);
    Log.d(TAG,"Value Print:: " + array1[i] + " ," + array1[i+1] );
}