gpt4 book ai didi

c - C语言简单的HTTP请求和响应

转载 作者:太空宇宙 更新时间:2023-11-03 23:44:15 25 4
gpt4 key购买 nike

<分区>

如何用 C 语言编写简单的 HTTP 请求和响应。

在 Java 中我可以使用:

    String url = "http://www.google.com/search?q=mkyong";

URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();

con.setRequestMethod("GET");

con.setRequestProperty("User-Agent", USER_AGENT);

int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

如何使用 C 语言实现?

我已经试过了 Here :但它无法正常工作。

大部分回复:

HTTP/1.1 301 Moved Permanently Location: http://www.google.co.in/ Content-Type: text/html; charset=UTF-8 Date: Mon, 27 Jun 2016 13:53:36 GMT Expires: Wed, 27 Jul 2016 13:53:36 GMT Cache-Control: public, max-age=2592000 Server: gws Content-Length: 221 X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="http://www.google.co.in/">here</A>. </BODY></HTML>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com