Two questions:
- How to set the address.family so requestHTTP will use a ipv4 address.
- Where do I find the enumeration for the address.family using AFINET results in the following compiler error :source/app.d(8,70): Error: undefined identifier 'AFINET'.
- How would I make it work using the web framework and/or the REST Interface.
The following code and execution output demonstrate the problem. In the first line a call to resolveHost with address family and use dns using the default an ipv6 address is returned [2607:f8b0:400d:c02:0:0:0:64]:0
The second line to resolveHost sets the address family set to 2 and use dns set to the default and ipv4 address is returned 98.124.44.234:0.
The call to requestHost results in the execution output detailed below. Essentially it Failed to connect to [2607:f8b0:400b:807:0:0:0:2004]:80 (Network is unreachable)
Any help is sincerely appreciated.
Thanks
John
import vibe.d;
import std.stdio;
import vibe.d;
import std.stdio;
void main()
{
writeln(" with address family and use dns not set ..",resolveHost("google.com"));
writeln(" with address family set to 2 ..",resolveHost("google.com",2));
writeln("");
requestHTTP("http://www.google.com/",
(scope req) {
req.method = HTTPMethod.POST;
//req.writeJsonBody(["name": "My Name"]);
},
(scope res) {
logInfo("Response: %s", res.bodyReader.readAllUTF8());
}
);
};
Performing "debug" build using dmd for x86_64.
vibe-d:utils 0.7.27: target for configuration "library" is up to date.
vibe-d:data 0.7.27: target for configuration "library" is up to date.
vibe-d:core 0.7.27: target for configuration "libevent" is up to date.
vibe-d:http 0.7.27: target for configuration "library" is up to date.
vibe-d:diet 0.7.27: target for configuration "library" is up to date.
vibe-d:mail 0.7.27: target for configuration "library" is up to date.
vibe-d:mongodb 0.7.27: target for configuration "library" is up to date.
vibe-d:redis 0.7.27: target for configuration "library" is up to date.
vibe-d:web 0.7.27: target for configuration "library" is up to date.
vibe-d 0.7.27: target for configuration "libevent" is up to date.
resolvetest ~master: building configuration "application"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
Running ./resolvetest
with address family and use dns not set ..[2607:f8b0:400d:c02:0:0:0:64]:0
with address family set to 2 ..98.124.44.234:0
std.exception.ErrnoException@../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/core/drivers/libevent2.d(320): Failed to connect to [2607:f8b0:400b:807:0:0:0:2004]:80 (Network is unreachable)
/usr/include/dmd/phobos/std/exception.d:615 @safe bool std.exception.enforceEx!(std.exception.ErrnoException).enforceEx!(bool).enforceEx(bool, lazy immutable(char)[], immutable(char)[], ulong) [0x822142]
../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/core/drivers/utils.d:59 @safe bool vibe.core.drivers.utils.socketEnforce!(bool).socketEnforce(bool, lazy immutable(char)[], immutable(char)[], ulong) [0x7e1146]
../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/core/drivers/libevent2.d:320 vibe.core.drivers.libevent2tcp.Libevent2TCPConnection vibe.core.drivers.libevent2.Libevent2Driver.connectTCP(vibe.core.net.NetworkAddress) [0x7d2e53]
../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/core/net.d:99 vibe.core.net.TCPConnection vibe.core.net.connectTCP(vibe.core.net.NetworkAddress) [0x7f04d0]
../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/core/net.d:95 vibe.core.net.TCPConnection vibe.core.net.connectTCP(immutable(char)[], ushort) [0x7f04a0]
../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/http/client.d:534 bool vibe.http.client.HTTPClient.doRequest(scope void delegate(vibe.http.client.HTTPClientRequest), bool*, bool, std.datetime.SysTime) [0x779102]
../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/http/client.d:472 bool vibe.http.client.HTTPClient.doRequestWithRetry(scope void delegate(vibe.http.client.HTTPClientRequest), bool, out bool, out std.datetime.SysTime) [0x778ebc]
../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/http/client.d:406 void vibe.http.client.HTTPClient.request(scope void delegate(scope vibe.http.client.HTTPClientRequest), scope void delegate(scope vibe.http.client.HTTPClientResponse)) [0x7789c1]
../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/http/client.d:121 void vibe.http.client.requestHTTP(vibe.inet.url.URL, scope void delegate(scope vibe.http.client.HTTPClientRequest), scope void delegate(scope vibe.http.client.HTTPClientResponse), vibe.http.client.HTTPClientSettings) [0x777c2a]
../../../../../../.dub/packages/vibe-d-0.7.27/source/vibe/http/client.d:106 void vibe.http.client.requestHTTP(immutable(char)[], scope void delegate(scope vibe.http.client.HTTPClientRequest), scope void delegate(scope vibe.http.client.HTTPClientResponse), vibe.http.client.HTTPClientSettings) [0x777993]
source/app.d:16 Dmain [0x6e41df]
??:? D2rt6dmain211drunmainUiPPaPUAAaZiZ6runAllMFZ9lambda1MFZv [0x87481a]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x874770]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x8747d6]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x874770]
??:? _d_run_main [0x8746cd]
??:? main [0x6f3917]
??:? libcstartmain [0xc5be7ec4]
Program exited with code 1