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

时间:2017-04-08 11:23:12

标签: java android connection httpconnection http-request-parameters

HTTPConnection conn 方法

setRequestProperty

conn.setRequestProperty("""&#34);

我对不同的网址有不同的标头。所以,它没有修复我的项目。  我需要使用数组来填充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] );
                    }
                }

1 个答案:

答案 0 :(得分: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] );
}