0
votes

I would like to post a json in my data base (RDF), My json is correct but i can't send it this is my code:

I would like to post this json into my database help plz ////////

HttpPost httppost=new HttpPost("http://www.hds.utc.fr/memorae/pr/api/swars/note");

         try {
             // JSON data:
            jsonA.put("index", "datjsonArray");//datjsonArray

                jsonA.put("sharingspace","datjsonArray1" );//datjsonArray1
                jsonA.put("content", "test");
                jsonA.put("title", "test");
                jsonA.put("aurhor", "amc2:userAPIConcept53a07a9a1758d");
                jsonA.put("distributor","datjsonArray2 ");//datjsonArray2
                jsonA.put("date", "dat");
                jsonA.put("type", "note"); 


             String json = jsonA.toString();



             StringEntity se = new StringEntity(json);  
             se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
             Log.i("se", ""+se);
             httppost.setEntity(se);
             HttpClient httpclient = new DefaultHttpClient();
             HttpResponse response = httpclient.execute(httppost);

             if(response!=null){
                 InputStream in = response.getEntity().getContent(); 
             }

         } catch(Exception e) {
             e.printStackTrace();
             Log.i("Error", "Cannot Estabilish Connection");
         }

error

07-05 02:10:06.410: E/NomDeMaClasse(2012): Erreur à tel endroit 07-05 02:10:06.410: E/NomDeMaClasse(2012): android.os.NetworkOnMainThreadException 07-05 02:10:06.410: E/NomDeMaClasse(2012): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at java.net.InetAddress.getAllByName(InetAddress.java:214) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at com.example.test.MainActivity$1.onClick(MainActivity.java:116) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at android.view.View.performClick(View.java:4438) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at android.view.View$PerformClick.run(View.java:18422) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at android.os.Handler.handleCallback(Handler.java:733) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at android.os.Handler.dispatchMessage(Handler.java:95) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at android.os.Looper.loop(Looper.java:136) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at android.app.ActivityThread.main(ActivityThread.java:5017) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at java.lang.reflect.Method.invokeNative(Native Method) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at java.lang.reflect.Method.invoke(Method.java:515) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 07-05 02:10:06.410: E/NomDeMaClasse(2012): at dalvik.system.NativeStart.main(Native Method)

3
You are getting an expcetion?Reda
Please post the exception, if you're getting one.Shivam Verma
i dont have any error or exceptionuser3804529
i would like to create a json like this : { "type" : "note", "index" : [ "Mandrin_Automatique", "Mandrin_Manuel" ], "distributor" : [ "amc2:userAPIConcept5388541197bcc" ], "author" : "amc2:userAPIConcept5388541197bcc", "content" : "Test", "sharingspace" : [ "ate:spaceAPIConcept539181b3a0d8d", "ate:spaceAPIConcept538888ab4848c" ], "date" : "04\/07\/2014", "title" : "test juillet" } and send in my data base (url) you can help me plzuser3804529
You are not getting error? Wel you are not reading the content your php script echos. You are only opening InputStream in but not reading from that stream. Add code which reads from the strem to get the echoed text. Display and log the text. It will contain error information.greenapps

3 Answers

0
votes

Change tthe two lines

json1.put("index", "datjsonArray");//datjsonArray
jsonA.put("aurhor", "amc2:userAPIConcept53a07a9a1758d");

to

jsonA.put("index", "datjsonArray");//datjsonArray
jsonA.put("author", "amc2:userAPIConcept53a07a9a1758d");

You will not get error messages from php anymore. Only a lot of odbc syntax errors messages. Probable reason: "datjsonArray" should be datjsonArray.

But... to see the messages you have to grab the echos from the php script by reading them from InputStream in.

0
votes

You have a serious exception

NetworkOnMainThreadExeption

Place your code in an AsyncTask or thread. AsyncTask is easiest. You can find many examples on this site.

If you only had posted the logcat earlier...

0
votes

ihave this error:i have this error olso :07-05 23:10:06.290: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg 07-05 23:10:06.300: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg 07-05 23:10:06.300: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg 07-05 23:10:06.300: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg 07-05 23:10:06.340: E/SoundPool(383): error loading /system/media/audio/ui/Effect_Tick.ogg 07-05 23:10:06.410: E/SoundPool(383): error loading /system/media/audio/ui/KeypressStandard.ogg 07-05 23:10:06.460: E/SoundPool(383): error loading /system/media/audio/ui/KeypressSpacebar.ogg 07-05 23:10:06.460: E/SoundPool(383): error loading /system/media/audio/ui/KeypressDelete.ogg 07-05 23:10:06.500: E/SoundPool(383): error loading /system/media/audio/ui/KeypressReturn.ogg 07-05 23:10:06.530: E/SoundPool(383): error loading /system/media/audio/ui/KeypressInvalid.ogg