I've done a webservice in java, now I'm switching to PHP and I'm having trouble implementing a page that receives via POST a JSON that the Android app sends.
ANDROID
public static String POST(Context context, String endereco, String json){
//Verifica se existe conexão com a internet
if(!existeConexao(context))
return K.FALHA_CONEXAO;
InputStream inputStream = null;
HttpClient httpClient = new DefaultHttpClient();
String result = null;
try{
HttpPost httpPost = new HttpPost(endereco);
httpPost.setEntity(new StringEntity(json, "UTF-8"));
httpPost.setHeader("Accept","application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse httpResponse = httpClient.execute(httpPost);
inputStream = httpResponse.getEntity().getContent();
if(inputStream!=null)
result = inputStreamParaString(inputStream);
else
result = K.FALHA;
}catch(UnsupportedEncodingException e){
e.printStackTrace();
}catch(ClientProtocolException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
return result;
}
WebService in JAVA
@Path("/enviarFeedBack/")
@POST
@Produces("application/json ; charset=UTF-8")
public String receberFeedBack(String json){
Feedback fb = new Gson().fromJson(json,Feedback.class);
fb.setData(new Date());
Integer result =
new FeedbackController().inserir(fb);
if(result == null || result<0 )
return K.FALHA;
else
return K.SUCESSO;
}
In short, in PHP I do not know the correct way to receive the data via POST that was sent by Android already tried to go through the array $_POST
but I do not know if this is correct, and I am also not able to send that response back success or failure.