我需要检查D中的服务器响应代码。例如,检查服务器是否返回404、200或其他代码。
我查看了std.net.curl,但是我不知道如何使用它。
我不确定,但可能需要使用选项请求ex:
import std.net.curl;
import std.stdio;
void main()
{
auto http = HTTP();
options("dlang.org", null, http);
writeln("Allow set to " ~ http.responseHeaders["Allow"]);
}
这个鳕鱼对我不起作用。我收到下一个错误:
F:\temp\1>app.exe
[email protected](8): Range violation
----------------
0x0041DB08
0x00402092
0x00426D8E
0x00426D63
0x00426C79
0x0041D857
0x7636338A in BaseThreadInitThunk
0x77C79F72 in RtlInitializeExceptionChain
0x77C79F45 in RtlInitializeExceptionChain
您只需附加一个statusLine回调:
auto http = HTTP("dlang.org");
http.onReceiveStatusLine = (HTTP.StatusLine status){ responceCode = status.code; };
//attach onreceive callback as well
http.perform();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句