HTTP非套接字web请求-D
如何发出GET和POSTHTTP请求?我找到了套接字解决方案,但全部解决了吗HTTP非套接字web请求-D,d,D,如何发出GET和POSTHTTP请求?我找到了套接字解决方案,但全部解决了吗 string host=“google.com”; ushort端口=80; 套接字侦听器=新的TcpSocket; 断言(listener.isAlive); listener.blocking=false; connect(新的InternetAddress(主机、端口)); char[]msg; char[]req=cast(char[])“GET/search.php HTTP/1.1\r\nHost:goog
string host=“google.com”;
ushort端口=80;
套接字侦听器=新的TcpSocket;
断言(listener.isAlive);
listener.blocking=false;
connect(新的InternetAddress(主机、端口));
char[]msg;
char[]req=cast(char[])“GET/search.php HTTP/1.1\r\nHost:google.com\r\n\r\n”;
发送(req);
看一看。它具有以下特点和方法:
导入std.net.curl;
auto-content=get(“d-lang.appspot.com/testUrl2”);
// --
自动内容=post(“d-lang.appspot.com/testUrl2”,[1,2,3,4]);
不可否认,curl是一个很好的解决方案。但是,这会给您的项目添加一个新的依赖项,对吗?根据您从事的项目类型,我建议您使用Adam Ruppe的arsd
模块,尤其是http
模块(他也在从事http2 one的工作)——。或者,如果您想要一个框架,那么vibe.d是您最好的选择(),因为它也有一个HTTP客户机。我推荐两本与vibe.d相关、面向web开发的书,它们列在下面的页面上:
更新:Python的请求包有一个很棒的端口,您应该试试:。您可以使用该库请求每个网站::
get示例:
import hunt.http;
import std.stdio;
void main()
{
auto client = new HttpClient();
auto request = new RequestBuilder().url("https://www.google.com").build();
auto response = client.newCall(request).execute();
if (response !is null)
{
writeln(response.getBody().asString());
}
}