Android JSON HttpClient to send data to PHP server with HttpResponse
After lots of reading and searching I have found the problem to be with, I beleive magic_quotes_gpc being enabled on the server.
Thus, using:
json_decode(stripslashes($_POST['vehicle']));
In my example above removes the slashes and allows the JSON to be decoded properly.
Still not sure why sending a StringEntity causes a 403 error?
StringEntity s = new StringEntity(c.toString());s.setContentEncoding("UTF-8");s.setContentType("application/json");request.setEntity(s);
Try this code it works for me
public void postData(String result,JSONObject obj) {// Create a new HttpClient and Post HeaderHttpClient httpclient = new DefaultHttpClient();HttpParams myParams = new BasicHttpParams();HttpConnectionParams.setConnectionTimeout(myParams, 10000);HttpConnectionParams.setSoTimeout(myParams, 10000);String json=obj.toString();try { HttpPost httppost = new HttpPost(result.toString()); httppost.setHeader("Content-type", "application/json"); StringEntity se = new StringEntity(obj.toString()); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); HttpResponse response = httpclient.execute(httppost); String temp = EntityUtils.toString(response.getEntity()); Log.i("tag", temp);} catch (ClientProtocolException e) {} catch (IOException e) {}
}