I have a simple web api which receives a parameter as string and return a "success" string as response. I have tested the api url with POSTMAN App and I got response as "success"
- url : http://www.xxx.co/testapi/testmethod
- Method : POST
- Params : key=val ; value=Hai
- Postman return as : "success"
My code in android is:
public static String tryPOSTScript(){
Log.d("TAG","App1 inside tryPOSTScript");
String data = "val=Hai";
URL url = null;
try {
url = new URL("http://www.xxx.co/testapi/testmethod");
} catch (MalformedURLException e) {
Log.d("TAG","App1 Exception MalformedURLException: "+e.toString());
e.printStackTrace();
}
HttpURLConnection con = null;
try {
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.getOutputStream().write(data.getBytes("UTF-8"));
con.getInputStream();
} catch (IOException e) {
Log.d("TAG","App1 Exception IOException: "+e.toString());
e.printStackTrace();
}
return data;
}
And I got the response as
Exception IOException: java.io.FileNotFoundException: http://www.xxx.co/testapi/testmethod Exception responseCode: 404
Please help to correct it. If file not found How can I get it correctly with postman app?