Android HttpClient为以下代码引发错误
inputstream在logcat中将输出显示为“org.apache.http.conn”。EofSensorInputStream@527021ec输出抛出错误。这是贝兹登录失败或我有任何错误的代码。Plz帮助…附上下面的logcat图像Android HttpClient为以下代码引发错误,android,Android,inputstream在logcat中将输出显示为“org.apache.http.conn”。EofSensorInputStream@527021ec输出抛出错误。这是贝兹登录失败或我有任何错误的代码。Plz帮助…附上下面的logcat图像 protected Void doInBackground(String... params) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost =
protected Void doInBackground(String... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(UrlLink);
try {
// Add user name and password
String username = "xaeroprasad";
String password = "ramesh88";
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("login", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.v("SENCIDE", "Execute HTTP Post Request");
HttpResponse response = httpclient.execute(httppost);
InputStream is=response.getEntity().getContent();
Log.v("ddd",is.toString());
String line = "";
StringBuilder total = new StringBuilder();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
Log.v("dfd",line);
} catch (IOException e) {
e.printStackTrace();
}
protectedvoiddoinbackground(字符串…参数){
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(URL链接);
试一试{
//添加用户名和密码
字符串username=“xaeroprasad”;
字符串密码=“ramesh88”;
List nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“登录”,用户名));
添加(新的BasicNameValuePair(“密码”,password));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
Log.v(“SENCIDE”,“执行HTTP Post请求”);
HttpResponse response=httpclient.execute(httppost);
InputStream is=response.getEntity().getContent();
Log.v(“ddd”,是.toString());
字符串行=”;
StringBuilder总计=新StringBuilder();
BufferedReader rd=新的BufferedReader(新的InputStreamReader(is));
试一试{
而((line=rd.readLine())!=null){
合计.追加(行);
}
对数v(“dfd”,行);
}捕获(IOE异常){
e、 printStackTrace();
}
Logcat输出:
您正在运行循环,直到
行
为空:
while ((line = rd.readLine()) != null) {
total.append(line);
}
当它结束(line==null
)时,您将打印行
:
Log.v("dfd",line);
这会引发错误,因为日志的第二个参数不能为null
您可能希望在循环后记录total
:
while ((line = rd.readLine()) != null) {
total.append(line);
}
Log.v("dfd", total);
试试看{
而((line=rd.readLine())!=null){
合计.追加(行);
}
对数v(“dfd”,总计)//
try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
Log.v("dfd",total); //<-- Edit this, its a Typo
} catch (IOException e) {
e.printStackTrace();
}