Thanks in advance…
i m using this code for set http header in http request for authenticate url..
but i think some what is mising thats why i could not get response…
response still comes like “authoriazation required”…
httpParameters = new BasicHttpParams();
String auth = android.util.Base64.encodeToString(
("florin999@zitec.ro" + ":" + "test2323" + ":" + "zitec"
+ ":" + "7716099f468cc71670b68cf4b3ba545c5760baa7")
.getBytes("UTF-8"), android.util.Base64.NO_WRAP);
HttpConnectionParams.setSoTimeout(httpParameters, 0);
client = new DefaultHttpClient(httpParameters);
String getURL = "URL here";
get = new HttpGet(getURL);
get.addHeader("Authorization", "Basic "+ auth);
// get.addHeader("X-ZFWS-Accept", "text/json");
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
//do something with the response
//Toast.makeText(Login.this.getApplicationContext(),EntityUtils.toString(resEntityGet), Toast.LENGTH_SHORT).show();
String s = EntityUtils.toString(resEntityGet);
tv1.setText(s);
}
}catch(Exception e){
}
plssss help me as soon as possible
Yor code is fine. you have the http client setup right and the header added right. but. your basic authentication is wrong. the header key (Authentication) is right but the value should be Basic + Base64.encode(username+”:”+pass)
also the alternative to that is the folowing code:
The target Hostname is probably null and the port -1.
but this one you wont be able to use if you are using url connection so a header is also acceptable.
EDIT:
HERE IS YOUR ISSUE:
What are all theese concatenations??
Basic authentication means adding a base64 encoded Authorization header which consisnt of the word
"Basic " + Base64.encodeToString("yourUsername"+":"+"yourPassword)The alternative is adding the method i pasted at the top about the credentials provider the same way