在嘗試不同的方法後,我無法從HttpResponse
檢索所有數據。無法檢索來自httpResponse的所有數據
這裏是我的代碼:
private static final DefaultHttpClient httpClient =
new DefaultHttpClient();
public void get() throws Exception {
HttpPost httpPost = new HttpPost("https://dt.abc.net/abc.exe");
httpPost.addHeader("Accept", "text/xml");
httpPost.setHeader("Content-Type","application/xml;charset=UTF-8")
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("XML",
getRequestTypeStringBuilder()));
// In here "XML" is parameter value that is required send to the server
// before request data from server.
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpConnectionParams.setSoTimeout(params, 5000);
httpClient.setParams(params);
httpClient.getParams().setParameter(
ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);
HttpResponse response = httpClient.execute(httpPost);
InputStream is = response.getEntity().getContent();
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buf;
int ByteRead;
buf = new byte[1024];
String xmldata = null;
while ((ByteRead = is.read(buf, 0, buf.length)) != -1) {
os.write(buf, 0, ByteRead);
totalSize += ByteRead;
}
xmldata = os.toString().replaceAll(" ", "");
os.close();
is.close();
}
的一個問題是,如果我設置內容類型=「application/xml進行」,並嘗試檢索從遠程服務器,這是在大量的數據,但它不能檢索所有數據。但是,如果數據相對較小,那麼它就是完美的。
所有返回數據是XML格式
如果我改變內容類型=「應用程序/ x WWW的形式進行了urlencoded」,它將引發和異常的另一個問題:
01-05 18:59:53.165: WARN/System.err(372): javax.net.ssl.SSLProtocolException: Read error: ssl=0x2f9698: Failure in SSL library, usually a protocol error
01-05 18:59:53.195: WARN/System.err(372): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
01-05 18:59:53.208: WARN/System.err(372): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:786)
01-05 18:59:53.215: WARN/System.err(372): at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
01-05 18:59:53.236: WARN/System.err(372): at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134)
01-05 18:59:53.236: WARN/System.err(372): at org.apache.http.impl.io.IdentityInputStream.read(IdentityInputStream.java:86)
01-05 18:59:53.246: WARN/System.err(372): at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:159)
01-05 18:59:53.286: WARN/System.err(372): at com.epsilon.android.dreammailandroid.remoteserver.AsyncDownloadDataInsert.doInBackground(AsyncDownloadDataInsert.java:111)
01-05 18:59:53.295: WARN/System.err(372): at com.epsilon.android.dreammailandroid.remoteserver.AsyncDownloadDataInsert.doInBackground(AsyncDownloadDataInsert.java:1)
01-05 18:59:53.316: WARN/System.err(372): at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-05 18:59:53.316: WARN/System.err(372): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-05 18:59:53.335: WARN/System.err(372): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-05 18:59:53.335: WARN/System.err(372): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-05 18:59:53.346: WARN/System.err(372): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-05 18:59:53.396: WARN/System.err(372): at java.lang.Thread.run(Thread.java:1019)
01-05 18:59:55.764: WARN/InputManagerService(61): Window already focused, ignoring focus gain of: [email protected]
我不能不明白爲什麼我無法獲得所有數據。
你能幫我,找出我的代碼中有什麼問題。
注意:我從android應用程序檢索數據。
謝謝
「願所有的幸福快樂」
問候和慈光, Ichirohang林布
你叫一些UI事件處理這個功能呢? – 2011-01-05 11:28:25
是的,我使用android AsyncTask。它有不同嗎? – user553710 2011-01-05 15:18:52
有沒有人注意到從代碼頂部的第8行有語法錯誤? 'httpPost.setHeader(「Content-Type」,「application/xml; charset = UTF-8」)' – 2011-07-05 05:39:29