未在服务器上添加Android HTTP基本身份验证

未在服务器上添加Android HTTP基本身份验证,android,http-headers,Android,Http Headers,我对web服务调用使用基本HTTP授权,它在我的本地机器上运行正常,但在托管服务器上没有相同的代码。它根本没有添加授权头。这是我使用的android代码 URL objurl = new URL(url); HttpURLConnection httpconn = (HttpURLConnection)objurl.openConnection(); httpconn.setRequestMethod("POST"); httpconn.setRequestProperty("Conte

我对web服务调用使用基本HTTP授权,它在我的本地机器上运行正常,但在托管服务器上没有相同的代码。它根本没有添加授权头。这是我使用的android代码

URL objurl = new URL(url);
HttpURLConnection httpconn =    (HttpURLConnection)objurl.openConnection();

httpconn.setRequestMethod("POST");
httpconn.setRequestProperty("Content-Type", 
       "application/x-www-form-urlencoded");
httpconn.setRequestProperty( "Accept", "*/*" );     

httpconn.setRequestProperty("Content-Length", "" + 
           Integer.toString(urlParameters.getBytes().length));  


String str_tm= "username:password";

byte[] encoded = Base64.encode(str_tm.getBytes("CP1252"), Base64.NO_WRAP);
String str = new String(encoded, "CP1252");

    httpconn.setRequestProperty("Authorization", "basic " + str);

httpconn.setRequestProperty("Content-Language", "en-US");  

httpconn.setUseCaches (false);
httpconn.setDoInput(true);
httpconn.setDoOutput(true);

//Send request
DataOutputStream wr = new DataOutputStream (
        httpconn.getOutputStream ());
wr.writeBytes (urlParameters);
wr.flush ();
wr.close (); 
来自服务器的响应标头是计算机,它们是:

"headers":
   { "Accept-Encoding":"gzip",
   "Connection":"close",
   "Host":"restaulogy.com",
   "User-Agent":"Dalvik\/2.1.0 (Linux; U; Android 5.1; sdk_phone_armv7 Build\/LKY45)",
   "Content-Language":"en-US","Content-Length":"30",
   "Accept":"*\/*",
   "Content-Type":"application\/x-www-form-urlencoded"
  }
来自本地计算机的请求头和请求头是:

"headers":
{
"Content-Type":"application\/x-www-form-urlencoded",
"Accept":"*\/*",
"Content-Length":"30",
"Authorization":"basic NjAyMjM3MTEzMTprcjJwTzJrTHorMFcvSGYwd3VWZFRNRzVzMGd5TXpCaE5USXdNekZs",
"Content-Language":"en-US",
"User-Agent":"Dalvik\/2.1.0 (Linux; U; Android 5.1; sdk_phone_armv7 Build\/LKY45)",
"Host":"192.168.1.112",
"Connection":"Keep-Alive",
"Accept-Encoding":"gzip"
}

查看响应“Authorization”标题缺失和“Connection”:“close”。有人能帮我吗?紧急。

您是否尝试使用
addRequestProperty()
而不是
。setRequestProperty(“Authorization”…)
?尝试过,但没有成功