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