【发布时间】:2014-05-01 01:42:52
【问题描述】:
显然我不是 android 或 java 专家。我想在我的 Android 应用程序中做的是,从服务器加载数据。我已经开始工作这部分并附上了源代码。但我想以一种安全的方式来做。作为第一步,我想用这样的用户名/密码来代替http://thisismyurl.com/a.php?action=get:http://username:password@thisismyurl.com/a.php?action=get 我该怎么做?我应该只将用户名和密码部分添加到 url 吗?
假设我已经完成了这将没有任何用处,因为有人可以打开 apk 并反编译源代码并获取 url 和用户名/密码。那么有没有真正安全的方法呢?
我希望我在这里得到理解。
String url = "http://thisismyurl.com/a.php?action=get";
String result = Web.executeWeb(url);
public class Web {
public static String executeWeb(final String url) {
final StringBuilder sb = new StringBuilder();
Thread thread = new Thread(new Runnable() {
public void run()
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String result, line = reader.readLine();
result = line;
while((line=reader.readLine())!=null){
result+=line;
}
sb.append(result);
//System.out.println(result);
//Log.i("My Response :: ", result);
} catch (Exception e)
{
// TODO: handle exception
}
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}
}
【问题讨论】:
标签: java android inputstream bufferedreader