从服务器的HTML响应 [英] HTML response from server

查看:335
本文介绍了从服务器的HTML响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序提出了一些从数据到本地服务器,因此服务器将发回一个JSON。说{状态:成功}

I have an app that submits some from data to a local server and as a result the server will send back a JSON. say {status:"success"}

它的工作,当我跑在我的2.3 SDK模拟器的应用程序,但安装在的Galaxy Tab(2.2 SDK)相同的响应是一个HTML的形式。

Its working when I run the app in my 2.3 SDK emulator, but installed in a Galaxy Tab (2.2 SDK) the same response is in the form of a 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>

编辑: 请求发送: -

Request sending:-

            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();

            }

任何一个可以告诉我什么是问题呢?

can any one tell me whats going wrong?

编码快乐..!

推荐答案

银河标签必须派出不同的页眉到仿真器。尝试禁用的期望头在你的HttpPost对象。

The Galaxy Tab must be sending different headers to the emulator. Try disabling the expectation header on your HttpPost object.

httppost.getParams().setBooleanParameter( "http.protocol.expect-continue", false )

另请参见<一href="http://stackoverflow.com/questions/5017751/expectation-failed-in-android-during-photo-upload">expectation照片中失败的Andr​​oid上传

这篇关于从服务器的HTML响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆