This question has been asked numerous times and my apologies for asking again. I've tried following numerous examples (Java - sending HTTP parameters via POST method easily) and blogs all without success.
I have this method
//POST
public static void MakeRequest(String uri, String data, boolean isError) {
try {
Log.i(TAG, data);
Log.i(TAG, uri);
byte[] bytes =data.getBytes();
// 2. make Connection
HttpURLConnection urlConnection = (HttpURLConnection) ((new URL(uri).openConnection()));
urlConnection.setRequestMethod("POST" );
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConnection.setRequestProperty("charset", "utf-8");
urlConnection.setRequestProperty("Content-Length", "" + Integer.toString(bytes.length));
urlConnection.setInstanceFollowRedirects(false);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches (false);
DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream ());
wr.write(bytes);
Log.i(TAG, "after send?");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
For making a call to my service. The service works fine for posting as I've been testing with Postman all with success. With my limited knowledge of Android/Java I am having a difficult time in figuring out why the above isn't working. I've walked through the debugger and no errors are thrown, the correct URL is used. What I cna't figure out is why the service is never being reaching.