1

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.

t00n
  • 395
  • 5
  • 12
  • follow this link https://stackoverflow.com/questions/21398598/how-to-post-raw-whole-json-in-the-body-of-a-retrofit-request**strong text** – J Prusty Jun 12 '18 at 10:27
  • Possible duplicate of [How to POST raw whole JSON in the body of a Retrofit request?](https://stackoverflow.com/questions/21398598/how-to-post-raw-whole-json-in-the-body-of-a-retrofit-request) – Kuba Spatny Jun 12 '18 at 13:24

1 Answers1

0

Finally, It's working! Seems like the port of my URL was giving some problems so I swapped it into another one and It's working now perfectly.

t00n
  • 395
  • 5
  • 12