如何将请求发送到已登录站点的其他页面
|
首先,我要连接到该站点。
之后,我想通过此连接从其他页面获取数据
样品:
1-通过用户密码连接到http://site.com/Login
2-从http://site.com/Secret获取机密数据
我该怎么做,请帮我...
OutputStreamWriter request = null;
url = new URL(\"http://site.com/Login\");
String response = null;
EditText user = (EditText)this.findViewById(R.id.user);
EditText pass = (EditText)this.findViewById(R.id.pass);
String parameters ;
try {
System.setProperty(\"http.keepAlive\", \"true\");
url = new URL(\"http://site.com/Home/Login\");
httppost = (HttpURLConnection) url.openConnection();
httppost.setDoInput(true);
httppost.setDoOutput(true);
httppost.setRequestMethod(\"POST\");
httppost.setRequestProperty(\"User-Agent\", \"Mozilla/5.0 Linux U Android 2.3.3 tr-tr HTC_DesireHD_A9191 Build/GRI40 AppleWebKit/533.1 KHTML, like Gecko Version/4.0 Mobile Safari/533.1\");
httppost.setRequestProperty(\"Accept_Language\", \"en-US\");
httppost.setRequestProperty(\"Connection\", \"Keep-Alive\");
httppost.setRequestProperty(\"Content-Type\", \"application/x-www-form-urlencoded\");
request = new OutputStreamWriter(httppost.getOutputStream());
parameters = \"username=\"+user.getText()+\"&password=\"+pass.getText();
request.write(parameters);
request.flush();
request.close();
String line = \"\";
InputStreamReader isr = new InputStreamReader(httppost.getInputStream());
BufferedReader reader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
sb.append(line + \"\\n\");
}
response = sb.toString();
Toast.makeText(this,response, Toast.LENGTH_LONG).show();
isr.close();
reader.close();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
没有找到相关结果
已邀请:
1 个回复
娠侈脚惮顽