在尝试不同的方式后,我无法从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();
}
问题是,如果我设置content-type =“application / xml”并尝试从远程服务器检索大量数据,则无法检索所有数据。但是,如果数据相对较小,那么它的工作非常完美。
所有返回数据均为XML格式
如果我更改content-type =“application / x-www-form-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: com.android.internal.view.IInputMethodClient$Stub$Proxy@4065a640
我无法理解为什么我无法获得所有数据作为回应。
你能帮助我,弄清楚我的代码中有什么问题。
注意:我从android应用程序中检索数据。
谢谢,
“愿所有人都快乐”
问候和Metta, Ichirohang Limbu
答案 0 :(得分:0)
如果返回的数据是text / xml,您可以尝试:
HttpResponse response = httpClient.execute(httpPost);
String content = EntityUtils.toString(response.getEntity());
答案 1 :(得分:0)
错误表示SSL级别或网络问题。这些问题中的任何一个都出现在Http协议错误下面的层中,我怀疑上面的连接类型建议可能没有密切关系。
javax.net.ssl.SSLProtocolException:读取错误:ssl = 0x2f9698:SSL库失败,通常是协议错误 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)
答案 2 :(得分:0)
尝试检查是否超时