我制作了一个执行 httpGet 的应用程序。
我的应用程序使用我自己的证书,因此服务器需要用户登录。对于证书,我使用了本教程。
对于 httpGet 我做了这个实现:
HttpClient client = new CustClient(getApplicationContext()); // HttpClient that uses my certificates
// Example send http request
final String url = "https://ip:port/";// <--in my implementation i've a right url
HttpResponse response = null;
HttpGet httpGet = new HttpGet(url);
//login
httpGet.addHeader("Authorization", "Basic "+Base64.encodeToString("root:root".getBytes(),Base64.DEFAULT));
StringBuilder testo = null;
try {
response = client.execute(httpGet);
InputStream contenuto = response.getEntity().getContent();
BufferedReader rd = new BufferedReader(new InputStreamReader(contenuto));
String line;
// Read response until the end
while ((line = rd.readLine()) != null) {
testo.append(line);
}
} catch (Exception e) {
}
为什么我让client.execute(httpGet)响应是 HTTP/1.1 400 Bad Request。为什么?在我的代码中进行身份验证是否正确?