Olá,
Utilizo AIDE (Android IDE) para criar aplicativos Android.
Montei o post conforme o código abaixo mas o site retorna a mesma página, o que estou fazendo de errado?
private class PutMethodDemo extends AsyncTask<String , Void ,String>
{
String server_response;
HttpResponse response;
String server_content = null;
@Override
protected String doInBackground(String... strings) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.consuladoportugalrjservicos.com/public_html/exec");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("modulo", "modulo.login"));
pairs.add(new BasicNameValuePair("acao", "login101"));
pairs.add(new BasicNameValuePair("txtcpf", "02355180776"));
pairs.add(new BasicNameValuePair("txtusuario","acastanheira2001@yahoo.com.br"));
pairs.add(new BasicNameValuePair("txtsenha", "senha_do_usuario"));
try
{
post.setEntity(new UrlEncodedFormEntity(pairs));
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
try
{
response = client.execute(post);
}
catch (IOException e)
{
e.printStackTrace();
}
Log.e("Response", "" + response.toString());
HttpEntity httpEntity = response.getEntity();
try
{
server_content = readStream(httpEntity.getContent());
}
catch (UnsupportedOperationException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
//final TextView textView1 = (TextView) findViewById(R.id.mainTextView1);
//textView1.setText(server_content);
//final EditText edittext1 = (EditText) findViewById(R.id.mainEditText1);
//edittext1.setText(server_content);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadData(server_content, "text/html", null);
Log.e("Response", "" + server_response);
Log.v("Response", "" + s);
}
// Converting InputStream to String
private String readStream(InputStream in) {
BufferedReader reader = null;
StringBuffer response = new StringBuffer();
try {
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
while ((line = reader.readLine()) != null) {
response.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return response.toString();
}
}