I have this java script code on my website which gets executed when someone subscribes to my newsletter. It is basically nothing but post request. This is the piece of code.
function es_submit_request(url, parameters, es_widget_form) {
http_req = false;
http_req.onreadystatechange = function() {eemail_submitresult(es_widget_form)}; // Passing the form to the submit request
http_req.open('POST', url, true);
http_req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_req.send(parameters);
}
Is is possible to call this post method from my android application code to subscribe someone to my newsletter?
I have tried this code here but it is not working.
When I debug my js code, variable values are coming as
parameters = "es_email=fgnfg@dgd.com&es_name=&es_group=×tamp=&action=0.9901232281510463"
url = "http://thetechguru.in/?es=subscribe"
I would highly appreciate if someone could help me with the code for this. I rather not use any library for this because I don't want overhead for such small thing. (for only one network call in my app)
This is the piece of code which I am trying but it is not working.
String urlString = "http://www.thetechguru.in/?es=subscribe&es_email=fsdsf@dgd.com&es_name=&es_group=×tamp=&action=0.9901232281510463";
String resultToDisplay = "";
InputStream in = null;
try {
URL url = new URL(urlString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
in = new BufferedInputStream(urlConnection.getInputStream());
} catch (Exception e) {
System.out.println(e.getMessage());
return e.getMessage();
}
try {
resultToDisplay = in.toString();//IOUtils.toString(in, "UTF-8");
//to [convert][1] byte stream to a string
Log.v("Response",resultToDisplay);
} catch (Exception e) {
e.printStackTrace();
}
Code executes, but nothing happens, email id is not added in list