我有一個從數據提交一些到本地服務器的應用程序,因此服務器將發回一個JSON。說{狀態:「成功」}來自服務器的HTML響應
它在我的2.3 SDK模擬器中運行應用程序,但安裝在Galaxy Tab(2.2 SDK)時工作,相同的響應是以HTML的形式。
I/RESPONSE(8190): <?xml version="1.0" encoding="utf-8"?>
I/RESPONSE(8190): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
I/RESPONSE(8190): "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
I/RESPONSE(8190): <html>
I/RESPONSE(8190): <head>
I/RESPONSE(8190): <title>417 Expectation Failed</title>
I/RESPONSE(8190): </head>
I/RESPONSE(8190): <body>
I/RESPONSE(8190): <h1>Error 417 Expectation Failed</h1>
I/RESPONSE(8190): <p>Expectation Failed</p>
I/RESPONSE(8190): <h3>Guru Meditation:</h3>
I/RESPONSE(8190): <p>XID: 1902486816</p>
I/RESPONSE(8190): <hr>
I/RESPONSE(8190): <address>
I/RESPONSE(8190): <a href="http://www.varnish-cache.org/">Varnish cache server</a>
I/RESPONSE(8190): </address>
I/RESPONSE(8190): </body>
I/RESPONSE(8190): </html>
I/RESPONSE(8190): <--
I/RESPONSE(8190):
I/RESPONSE(8190): <?xml version="1.0" encoding="utf-8"?>
I/RESPONSE(8190): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
I/RESPONSE(8190): "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
I/RESPONSE(8190): <html>
I/RESPONSE(8190): <head>
I/RESPONSE(8190): <title>417 Expectation Failed</title>
I/RESPONSE(8190): </head>
I/RESPONSE(8190): <body>
I/RESPONSE(8190): <h1>Error 417 Expectation Failed</h1>
I/RESPONSE(8190): <p>Expectation Failed</p>
I/RESPONSE(8190): <h3>Guru Meditation:</h3>
I/RESPONSE(8190): <p>XID: 1902486816</p>
I/RESPONSE(8190): <hr>
I/RESPONSE(8190): <address>
I/RESPONSE(8190): <a href="http://www.varnish-cache.org/">Varnish cache server</a>
I/RESPONSE(8190): </address>
I/RESPONSE(8190): </body>
I/RESPONSE(8190): </html>
W/System.err(8190): org.json.JSONException: A JSONObject text must begin with '{' at character 2 of
W/System.err(8190): <?xml version="1.0" encoding="utf-8"?>
W/System.err(8190): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
W/System.err(8190): "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
W/System.err(8190): <html>
W/System.err(8190): <head>
W/System.err(8190): <title>417 Expectation Failed</title>
W/System.err(8190): </head>
W/System.err(8190): <body>
W/System.err(8190): <h1>Error 417 Expectation Failed</h1>
W/System.err(8190): <p>Expectation Failed</p>
W/System.err(8190): <h3>Guru Meditation:</h3>
W/System.err(8190): <p>XID: 1902486816</p>
W/System.err(8190): <hr>
W/System.err(8190): <address>
W/System.err(8190): <a href="http://www.varnish-cache.org/">Varnish cache server</a>
W/System.err(8190): </address>
W/System.err(8190): </body>
W/System.err(8190): </html>
編輯: 請求發送: -
try {
HttpClient client = new DefaultHttpClient();
String postURL = GlobalCodes.getBaseurl();
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("show",
"testpost"));
post.setEntity(new UrlEncodedFormEntity(params));
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
String str2 = EntityUtils.toString(resEntity);
Log.i("RESPONSE", " <--");
if (resEntity != null) {
Log.i("RESPONSE","**");
JSONObject jsonObj = new JSONObject(str2);
if (jsonObj.getString("status").equalsIgnoreCase("succuss")) {
.....
} else {
......
}
}
} catch (Exception e) {
e.printStackTrace();
}
任何一個可以告訴我什麼問題呢?
快樂編碼..!
你從服務器得到錯誤,這就是爲什麼這種類型的數據得到迴應。 – user370305
嘗試處理服務器端的錯誤,查看從您的應用程序發送請求時服務器獲得的數據類型以及服務器如何處理它。 – user370305
在您發送請求的地方顯示您的代碼。 – user370305