-1

「ユーザーアカウントを作成する」ことをしなければなりません。json をサーバーに送信し、結果である別の json を取得する必要があります。では、json をサーバーに送信し、別の json を取得するにはどうすればよいでしょうか?

送信する必要があるjsonオブジェクトを作成しました。

ベローは、私が学んだことに基づいた現在の試みですが、まだそこにはありません。

私が送信している json が呼び出されuserCreate、url 文字列が呼び出されpathます。

create.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                    Thread t = new Thread() {

                        public void run() {
                            Looper.prepare(); //For Preparing Message Pool for the child Thread
                            HttpClient client = new DefaultHttpClient();
                            HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
                            HttpResponse response;

                            try {
                                HttpPost post = new HttpPost(path);
                                StringEntity se = new StringEntity( userCreate.toString());  
                                se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                                post.setEntity(se);
                                response = client.execute(post);

                                /*Checking response */
                                if(response!=null){
                                    InputStream in = response.getEntity().getContent(); //Get the data in the entity
                                    Toast.makeText(ctx, in.toString(), 2000).show();
                                }

                            } catch(Exception e) {
                                e.printStackTrace();
                                Toast.makeText(ctx, "nu merge", 2000).show();
                            }
                        }
                    };

                    t.start();    

                }

        });


09-17 13:45:29.337: D/request(5838):  {"request":{"action":"createUser","user":{"last_name":"asd","first_name":"asd","username":"asd","password":"d41d8cd98f00b204e9800998ecf8427e","email":"asd@yahoo.com"}}}
09-17 13:45:29.337: W/System.err(5838): android.os.NetworkOnMainThreadException
09-17 13:45:29.337: W/System.err(5838):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
09-17 13:45:29.337: W/System.err(5838):     at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
09-17 13:45:29.337: W/System.err(5838):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
09-17 13:45:29.337: W/System.err(5838):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
09-17 13:45:29.337: W/System.err(5838):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
09-17 13:45:29.337: W/System.err(5838):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-17 13:45:29.337: W/System.err(5838):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-17 13:45:29.337: W/System.err(5838):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
09-17 13:45:29.337: W/System.err(5838):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-17 13:45:29.337: W/System.err(5838):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-17 13:45:29.337: W/System.err(5838):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-17 13:45:29.337: W/System.err(5838):     at com.xcommerce.androidstore.Profile.postJson(Profile.java:123)
09-17 13:45:29.337: W/System.err(5838):     at com.xcommerce.androidstore.Profile$1.onClick(Profile.java:70)
09-17 13:45:29.337: W/System.err(5838):     at android.view.View.performClick(View.java:4202)
09-17 13:45:29.337: W/System.err(5838):     at android.view.View$PerformClick.run(View.java:17340)
09-17 13:45:29.337: W/System.err(5838):     at android.os.Handler.handleCallback(Handler.java:725)
09-17 13:45:29.337: W/System.err(5838):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-17 13:45:29.337: W/System.err(5838):     at android.os.Looper.loop(Looper.java:137)
09-17 13:45:29.337: W/System.err(5838):     at android.app.ActivityThread.main(ActivityThread.java:5039)
09-17 13:45:29.337: W/System.err(5838):     at java.lang.reflect.Method.invokeNative(Native Method)
09-17 13:45:29.337: W/System.err(5838):     at java.lang.reflect.Method.invoke(Method.java:511)
09-17 13:45:29.337: W/System.err(5838):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-17 13:45:29.337: W/System.err(5838):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-17 13:45:29.337: W/System.err(5838):     at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1