我实现了一个 Java 代码,它可以向远程网站发送请求并从中检索数据。但是我想要 C 中的相同代码,但是我在 C 库中找不到这么多的帮助。任何机构都可以给我任何提示吗?
public static String getHTML(String urlToRead) {
URL url;
HttpURLConnection conn;
BufferedReader rd;
String line;
String result = "";
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result += line;
}
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) throws IOException {
InetAddress thisIp = null;
try {
thisIp = InetAddress.getLocalHost();
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
System.out.println(getHTML("http://api.hostip.info/get_html.php?ip="
+ thisIp.getHostAddress()));
}