【发布时间】:2012-02-20 13:13:38
【问题描述】:
我有以下代码,它接受一个普通的 HTTP GET 请求并将输出的 html 作为字符串返回。
public static String getURLContent(String URL){
String Result = "";
String IP = "http://localhost/";
try {
// Create a URL for the desired page
URL url = new URL(IP.concat(URL));
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
Result = Result+str+"~";
}
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return Result;
}
我想为未签名的 ssl 证书实现同样的事情,但我在 Java 或 Android 编程方面有点新手,发现以前对类似问题的一些回答非常令人困惑。
有人可以更改上面的代码以处理 HTTPS 请求吗?
另一个问题,如果我通过 GET 请求发送未加密的数据并将数据库条目打印到函数返回其内容的网页上,是否会有中间人攻击的风险。使用 POST 请求会更好吗?
我选择使用 SSL 的原因是因为有人告诉我发送的数据是加密的。数据是敏感的,如果我发送类似 localhost/login.php?user=jim&password=sd7vbsksd8 的内容,它将返回“user=jim permission=admin age=23”,这是我不希望其他人看到的数据,如果他们只是使用浏览器并发送相同的请求。
【问题讨论】:
标签: android ssl https get request