我用java来模拟GET方法。第三个参数“auth”是基本的 http 身份验证示例。
http://en.wikipedia.org/wiki/Basic_access_authentication
http://en.wikipedia.org/wiki/BASE64
public String sendGet(String url, String param, String auth) {
String result = "";
BufferedReader in = null;
try {
String urlName = url + "?" + param;
URL realUrl = new URL(urlName);
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
conn.setRequestProperty("Accept", "application/json");
conn.addRequestProperty("Authorization", "Basic " + auth);
conn.connect();
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}