私はサイトを持っています
http://otu-git.dyndns.ws/pvm_srv/echo_json.html
入力すると
{
"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 アプローチを使用したときに得られる操作です
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): ################################