Я использовал httppost для отправки объекта json с android в мой php-файл, мой java-код
JSONObject json = new JSONObject();
try
{
json.put("email", "15");
}
catch (JSONException e)
{
e.printStackTrace();
}
String url = "http://xxxx.in/xxx/xxx.php";
HttpResponse re;
String temp = new String();
try
{
re = HTTPPoster.doPost(url, json);
temp = EntityUtils.toString(re.getEntity());
Log.d("Main",temp);
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
if (temp.compareTo("SUCCESS")==0)
{
Toast.makeText(this, "Sending complete!", Toast.LENGTH_LONG).show();
}
public class HTTPPoster
{
public static HttpResponse doPost(String url, JSONObject c) throws ClientProtocolException, IOException
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
HttpEntity entity;
StringEntity s = new StringEntity(c.toString());
s.setContentEncoding((Header) new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
entity = s;
request.setEntity(entity);
HttpResponse response;
response = httpclient.execute(request);
return response;
}
}
и мой php код
$data = json_decode( $_POST['json'] );
echo $data['email'];
echo "working";
* Только 1006 * Работа возвращается назад. Я не получаю контент $ data ['email']