I am trying to send two parameters to my webservice through POST and I am presented with the error android.os.NetworkOnMainThreadException
, when trying to execute the line of code
String respuesta = mRequest.execute(nameValuePairs);
The code of my class is as follows.
public class ConexionWS implements MInterfarceTask {
JsonObjectRequest jsonObjectRequest;
RequestQueue request;
Context getApplicationContext;
String codigo, passw;
private String url;
@Override
public void onPreExecute() {
}
@Override
public void doInBackground() {
url = "http://10.20.91.61/carnet/webServiceCarnet.php";
try {
MRequest mRequest = new MRequest(new URL(url));
LinkedHashMap<String, String> nameValuePairs = new LinkedHashMap<String, String>();
nameValuePairs.put("documento", codigo);
nameValuePairs.put("pass", passw);
String respuesta = mRequest.execute(nameValuePairs);
JSONObject jsonObject = new JSONObject(respuesta);
} catch (JSONException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Please help me how to solve this error. or if there is another method to send data through POST more effective let me know. THANK YOU