它刚刚退出。有什么问题?
我找不到任何错误。
如果有更好的方法将XML下载到输入流,请告诉我。
或者同时阅读3个或更多XML的好方法
package com.some.some;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.os.Bundle;
import android.app.Activity;
import android.util.Base64;
import android.view.Menu;
import android.view.View;
public class Login extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
InputStream stream1 = downloadXmlFileStreamUsingUrl("URL IS CORRECT :|");
// Parse check is login or not ...
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
public InputStream downloadXmlFileStreamUsingUrl(final String url) {
final HttpGet getRequest = new HttpGet(url);
String encodedStr = Base64.encodeToString("user:pass".getBytes(), 0);
getRequest.setHeader("Authorization", "Basic " + encodedStr);
HttpClient client = null;
try {
client = new DefaultHttpClient();
client.getConnectionManager();
final HttpResponse getResponse = client.execute(getRequest);
final int statusCode = getResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
return null;
}
final HttpEntity getResponseEntity = getResponse.getEntity();
final InputStream content = getResponseEntity.getContent();
return content;
} catch (final IOException e) {
getRequest.abort();
}
finally {
client.getConnectionManager().shutdown();
}
return null;
}
}