I have been programming for little time in Android Studio and I have been trying to send a JSON to my IIS Server in several different ways(Retrofit2, Volley, HttpClient...) and I never manage to do it properly since my IIS APP don't introduce a new row in my Mysql BBDD.
This method is from my IIS APP which receives a Json, converts it to an Object and then, do a query to my BBDD and introduce a new row.
public String Post([FromBody] Empleado empleado)
{}
This method is working fine because I have tried it from an IIS Console App and it works perfectly
Two Examples of what I'm doing in Android Studio:
Volley:
public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
enviarDatos();
}
public void enviarDatos(){
String url ="http://...myurl";
textView = (TextView)findViewById(R.id.text);
try {
RequestQueue requestQueue = Volley.newRequestQueue(this);
final org.json.JSONObject jsonBody = new org.json.JSONObject();
jsonBody.put("idTag",112353);
jsonBody.put("Longitud","1253");
jsonBody.put("Latitud","Test");
JsonObjectRequest request = new JsonObjectRequest
(Request.Method.POST, url, jsonBody, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
textView.setText(response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
textView.setText(error.toString());
}
});
requestQueue.add(request);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
Any help would be grateful, thanks for your comments and sorry for my bad English
Edit: Finally It's working! Seems like the port of my URL was giving some problems so I swapped it and It's working now perfectly.