When I send a parameter through POST to a URL, I'm redirected to another URL, it's redirecting me to the right URL, but it returns me:
<script LANGUAGE=JavaScript>alert('Seu tempo expirou. Por favor entre novamente');location.href='logon.asp';</script>
My Activity Code:
public class HttpPostAsyncTask extends AsyncTask<String,Void,String> {
@Override
protected String doInBackground(String... param) {
content = new StringBuilder();
String response= "";
try {
URL link = new URL(url+path);
HttpURLConnection.setFollowRedirects(true);
HttpURLConnection conn = (HttpURLConnection) link.openConnection();
conn.setInstanceFollowRedirects(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
String charset = "UTF-8";
String s = "txtnumero_matricula=" + URLEncoder.encode(login, charset);
s += "&txtsenha_tac=" + URLEncoder.encode(senha, charset);
s += "&cmdEnviar=" + URLEncoder.encode(param, charset);
conn.setFixedLengthStreamingMode(s.getBytes().length);
PrintWriter out = new PrintWriter(conn.getOutputStream());
out.print(s);
out.close();
System.out.print(conn.getURL());
conn.connect();
Scanner inStream = new Scanner(conn.getInputStream());
while(inStream.hasNextLine())
response += (inStream.nextLine());
System.out.println(conn.getURL()+" "+response);
} catch (ProtocolException e1) {
e1.printStackTrace();
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
return response.toString();
}
@Override
protected void onPostExecute(String html) {
super.onPostExecute(html);
}
}
I made more tests and any parameter that I sent, right or wrong, it returns the same SCRIPT.