Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android JSON HTTP-POST_Android_Json_Http Post - Fatal编程技术网

Android JSON HTTP-POST

Android JSON HTTP-POST,android,json,http-post,Android,Json,Http Post,我有一个网站 我打字的时候 { "USR": { "fun": "validarUsuario", "txtUser":"123", "md5Passwd": "123" } } 它回来了 {"success":"true","nombre":"test"} 我想在Android中实现同样的功能。我想提取“真实”和“测试”部分。 为此,我已经实现了代

我有一个网站

我打字的时候

    {
         "USR": {
             "fun": "validarUsuario",
             "txtUser":"123",
             "md5Passwd": "123"
         }   
     }  
它回来了

{"success":"true","nombre":"test"}
我想在Android中实现同样的功能。我想提取“真实”和“测试”部分。 为此,我已经实现了代码

HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "http://otu-git.dyndns.ws/pvm_srv/echo_json.html");
        HttpEntity entity;

        // TextView textView = (TextView) findViewById(R.id.textView1);

        JSONObject json = new JSONObject();

        JSONObject header = new JSONObject();

        try {

            json.put("txtUser", "123");
            json.put("md5Passwd", "123");
            json.put("fun", "validarUsuario");

            header.put("USR", json);

            se = new StringEntity(header.toString());

        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        try {

            httppost.setEntity(se);
            HttpResponse response = httpclient.execute(httppost);
            entity = response.getEntity();
            // String jsonResult =
            // inputStreamToString(response.getEntity().getContent()).toString();
            // JSONObject object = new JSONObject(jsonResult);

            // String name = object.getString("name");
            // String verion = object.getString("version");
            Log.i("dhiraj", header.toString());

            Toast t = Toast.makeText(getApplicationContext(),
                    response.toString(), Toast.LENGTH_LONG);
            t.show();
            // textView.setText(response.toString());

            Log.i("dhiraj", response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
但是我收到了输出

org.apache.http.message.BasicHttpResponse@4140cbe0
这是我使用bufferedReader方法时得到的op

11-06 21:43:06.671: I/dhiraj(6615): <html>
11-06 21:43:06.671: I/dhiraj(6615): <body>
11-06 21:43:06.671: I/dhiraj(6615):     <form ID="fname" action="serv.php" method="POST">
11-06 21:43:06.671: I/dhiraj(6615):         <textarea name="json" rows="30" cols="120">
11-06 21:43:06.671: I/dhiraj(6615):          {
11-06 21:43:06.671: I/dhiraj(6615):              "CLI": {
11-06 21:43:06.671: I/dhiraj(6615):                  "fun": "obtenerListaCliente",
11-06 21:43:06.671: I/dhiraj(6615):                  "txtUser":"123",
11-06 21:43:06.671: I/dhiraj(6615):                  "md5Passwd": "321"
11-06 21:43:06.671: I/dhiraj(6615):              }
11-06 21:43:06.671: I/dhiraj(6615):          }
11-06 21:43:06.671: I/dhiraj(6615):         </textarea>
11-06 21:43:06.671: I/dhiraj(6615):         <input type="submit" value="enviar" name="enviar">
11-06 21:43:06.671: I/dhiraj(6615):     </form>
11-06 21:43:06.671: I/dhiraj(6615): <script>
11-06 21:43:06.671: I/dhiraj(6615):     var frm = document.getElementById('fname');
11-06 21:43:06.671: I/dhiraj(6615): #    if (frm) {
11-06 21:43:06.671: I/dhiraj(6615): #        frm.submit();
11-06 21:43:06.671: I/dhiraj(6615): #    }
11-06 21:43:06.671: I/dhiraj(6615): <iframe id="myframe" src="/default.asp" scrolling="auto">
11-06 21:43:06.671: I/dhiraj(6615): </script>
11-06 21:43:06.671: I/dhiraj(6615): <pre>
11-06 21:43:06.671: I/dhiraj(6615): ########################################################################
11-06 21:43:06.671: I/dhiraj(6615): #
11-06 21:43:06.671: I/dhiraj(6615): #    CLIENTE
11-06 21:43:06.671: I/dhiraj(6615): #
11-06 21:43:06.671: I/dhiraj(6615): ########################################################################
11-06 21:43:06.671: I/dhiraj(6615):     #    obtenerListaCliente                                           #
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):         {
11-06 21:43:06.671: I/dhiraj(6615):              "CLI": {
11-06 21:43:06.671: I/dhiraj(6615):                  "fun": "obtenerListaCliente",
11-06 21:43:06.671: I/dhiraj(6615):                  "txtUser":"123",
11-06 21:43:06.671: I/dhiraj(6615):                  "md5Passwd": "123"
11-06 21:43:06.671: I/dhiraj(6615):              }   
11-06 21:43:06.671: I/dhiraj(6615):          }  
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):     #    obtenerCSVclientes                                            #
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):          {
11-06 21:43:06.671: I/dhiraj(6615):              "CLI":{
11-06 21:43:06.671: I/dhiraj(6615):                  "fun":"obtenerCSVclientes",
11-06 21:43:06.671: I/dhiraj(6615):                  "txtUser":"123",
11-06 21:43:06.671: I/dhiraj(6615):                  "md5Passwd":"123"
11-06 21:43:06.671: I/dhiraj(6615):              }
11-06 21:43:06.671: I/dhiraj(6615):          }
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):     #    obtenerCSVhorarios                                            #
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):          {
11-06 21:43:06.671: I/dhiraj(6615):              "CLI":{
11-06 21:43:06.671: I/dhiraj(6615):                  "fun":"obtenerCSVhorarios",
11-06 21:43:06.671: I/dhiraj(6615):                  "txtUser":"123",
11-06 21:43:06.671: I/dhiraj(6615):                  "md5Passwd":"123"
11-06 21:43:06.671: I/dhiraj(6615):              }
11-06 21:43:06.671: I/dhiraj(6615):          }
11-06 21:43:06.671: I/dhiraj(6615): ########################################################################
11-06 21:43:06.671: I/dhiraj(6615): #
11-06 21:43:06.671: I/dhiraj(6615): #    USUARIO
11-06 21:43:06.671: I/dhiraj(6615): #
11-06 21:43:06.671: I/dhiraj(6615): ########################################################################
11-06 21:43:06.671: I/dhiraj(6615):     #    ValidarUsuario                                                #
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):         {
11-06 21:43:06.671: I/dhiraj(6615):              "USR": {
11-06 21:43:06.671: I/dhiraj(6615):                  "fun": "validarUsuario",
11-06 21:43:06.671: I/dhiraj(6615):                  "txtUser":"123",
11-06 21:43:06.671: I/dhiraj(6615):                  "md5Passwd": "123"
11-06 21:43:06.671: I/dhiraj(6615):              }   
11-06 21:43:06.671: I/dhiraj(6615):          }  
11-06 21:43:06.671: I/dhiraj(6615): ########################################################################
11-06 21:43:06.671: I/dhiraj(6615): #
11-06 21:43:06.671: I/dhiraj(6615): #    ZONAS
11-06 21:43:06.671: I/dhiraj(6615): #
11-06 21:43:06.671: I/dhiraj(6615): ########################################################################
11-06 21:43:06.671: I/dhiraj(6615):     #    obtenerCSVzonas                                               #
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):         {
11-06 21:43:06.671: I/dhiraj(6615):              "ZON":{
11-06 21:43:06.671: I/dhiraj(6615):                  "fun":"obtenerCSVzonas",
11-06 21:43:06.671: I/dhiraj(6615):                  "txtUser":"123",
11-06 21:43:06.671: I/dhiraj(6615):                  "md5Passwd":"123"
11-06 21:43:06.671: I/dhiraj(6615):              }
11-06 21:43:06.671: I/dhiraj(6615):         }
11-06 21:43:06.671: I/dhiraj(6615): ########################################################################
11-06 21:43:06.671: I/dhiraj(6615): #
11-06 21:43:06.671: I/dhiraj(6615): #    PRODUCTOS
11-06 21:43:06.671: I/dhiraj(6615): #
11-06 21:43:06.671: I/dhiraj(6615): ########################################################################
11-06 21:43:06.671: I/dhiraj(6615):     #    obtenerCSVproductos                                           #
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):         {
11-06 21:43:06.671: I/dhiraj(6615):              "PRO":{
11-06 21:43:06.671: I/dhiraj(6615):                  "fun":"obtenerCSVproductos",
11-06 21:43:06.671: I/dhiraj(6615):                  "txtUser":"123",
11-06 21:43:06.671: I/dhiraj(6615):                  "md5Passwd":"123"
11-06 21:43:06.671: I/dhiraj(6615):              }
11-06 21:43:06.671: I/dhiraj(6615):         }
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):     #    obtenerCSVproductosFrec                                       #
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):         {
11-06 21:43:06.671: I/dhiraj(6615):              "PRO":{
11-06 21:43:06.671: I/dhiraj(6615):                  "fun":"obtenerCSVproductosFrec",
11-06 21:43:06.671: I/dhiraj(6615):                  "txtUser":"123",
11-06 21:43:06.671: I/dhiraj(6615):                  "md5Passwd":"123"
11-06 21:43:06.671: I/dhiraj(6615):              }
11-06 21:43:06.671: I/dhiraj(6615):         }
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):     #    obtenerCSVprecios                                             #
11-06 21:43:06.671: I/dhiraj(6615):     ####################################################################
11-06 21:43:06.671: I/dhiraj(6615):         {
11-06 21:43:06.671: I/dhiraj(6615):              "PRO":{
11-06 21:43:06.671: I/dhiraj(6615):                  "fun":"obtenerCSVprecios",
11-06 21:43:06.671: I/dhiraj(6615):                  "txtUser":"123",
11-06 21:43:06.671: I/dhiraj(6615):                  "md5Passwd":"123"
11-06 21:43:06.671: I/dhiraj(6615):              }
11-06 21:43:06.671: I/dhiraj(6615):         }
11-06 21:43:06.671: I/dhiraj(6615): ################################
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):{
11-0621:43:06.671:I/dhiraj(6615):“CLI”:{
11-0621:43:06.671:I/dhiraj(6615):“乐趣”:“obtenerlistaclient”,
11-0621:43:06.671:I/dhiraj(6615):“txtUser”:“123”,
11-0621:43:06.671:I/dhiraj(6615):“md5Passwd”:“321”
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):var frm=document.getElementById('fname');
11-0621:43:06.671:I/dhiraj(6615):#如果(frm){
11-0621:43:06.671:I/dhiraj(6615):#frm.submit();
11-0621:43:06.671:I/dhiraj(6615):#
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):
11-0621:43:06.671:I/dhiraj(6615):########################################################################
11-0621:43:06.671:I/dhiraj(6615):#
11-0621:43:06.671:I/dhiraj(6615):#客户
11-0621:43:06.671:I/dhiraj(6615):#
11-0621:43:06.671:I/dhiraj(6615):########################################################################
11-0621:43:06.671:I/dhiraj(6615):#obtenerlistaclient#
11-0621:43:06.671:I/dhiraj(6615):####################################################################
11-0621:43:06.671:I/dhiraj(6615):{
11-0621:43:06.671:I/dhiraj(6615):“CLI”:{
11-0621:43:06.671:I/dhiraj(6615):“乐趣”:“obtenerlistaclient”,
11-0621:43:06.671:I/dhiraj(6615):“txtUser”:“123”,
11-0621:43:06.671:I/dhiraj(6615):“md5Passwd”:“123”
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):####################################################################
11-0621:43:06.671:I/dhiraj(6615):#获得客户#
11-0621:43:06.671:I/dhiraj(6615):####################################################################
11-0621:43:06.671:I/dhiraj(6615):{
11-0621:43:06.671:I/dhiraj(6615):“CLI”:{
11-0621:43:06.671:I/dhiraj(6615):“乐趣”:“获得客户”,
11-0621:43:06.671:I/dhiraj(6615):“txtUser”:“123”,
11-0621:43:06.671:I/dhiraj(6615):“md5Passwd”:“123”
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):####################################################################
11-0621:43:06.671:I/dhiraj(6615):#obtenerCSVhorarios#
11-0621:43:06.671:I/dhiraj(6615):####################################################################
11-0621:43:06.671:I/dhiraj(6615):{
11-0621:43:06.671:I/dhiraj(6615):“CLI”:{
11-0621:43:06.671:I/dhiraj(6615):“乐趣”:“obtenerCSVhorarios”,
11-0621:43:06.671:I/dhiraj(6615):“txtUser”:“123”,
11-0621:43:06.671:I/dhiraj(6615):“md5Passwd”:“123”
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):########################################################################
11-0621:43:06.671:I/dhiraj(6615):#
11-0621:43:06.671:I/dhiraj(6615):#乌萨里奥
11-0621:43:06.671:I/dhiraj(6615):#
11-0621:43:06.671:I/dhiraj(6615):########################################################################
11-0621:43:06.671:I/dhiraj(6615):#Validarusario#
11-0621:43:06.671:I/dhiraj(6615):####################################################################
11-0621:43:06.671:I/dhiraj(6615):{
11-0621:43:06.671:I/dhiraj(6615):“USR”:{
11-0621:43:06.671:I/dhiraj(6615):“乐趣”:“Validarusario”,
11-0621:43:06.671:I/dhiraj(6615):“txtUser”:“123”,
11-0621:43:06.671:I/dhiraj(6615):“md5Passwd”:“123”
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):########################################################################
11-0621:43:06.671:I/dhiraj(6615):#
11-0621:43:06.671:I/dhiraj(6615):#佐纳斯
11-0621:43:06.671:I/dhiraj(6615):#
11-0621:43:06.671:I/dhiraj(6615):########################################################################
11-0621:43:06.671:I/dhiraj(6615):#obtenerCSVzonas#
11-0621:43:06.671:I/dhiraj(6615):####################################################################
11-0621:43:06.671:I/dhiraj(6615):{
11-0621:43:06.671:I/dhiraj(6615):“宗”:{
11-0621:43:06.671:I/dhiraj(6615):“乐趣”:“奥普坦茨维佐纳斯”,
11-0621:43:06.671:I/dhiraj(6615):“txtUser”:“123”,
11-0621:43:06.671:I/dhiraj(6615):“md5Passwd”:“123”
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):}
11-0621:43:06.671:I/dhiraj(6615):#################################################
BufferedReader rd = new BufferedReader(new InputStreamReader(
                response.getEntity().getContent()));

    StringWriter sw = new StringWriter();
    char[] buffer = new char[1024 * 4];
    int n = 0;
    while (-1 != (n = rd.read(buffer))) {
        sw.write(buffer, 0, n);
    }
    String resultString = sw.toString();
{"success":"true","nombre":"test"}