RejectedSoftware Forums

Sign up

getting invalid request with requestHTTP

Hello,

I have the following "requestHTTP" setup and Im getting back an "invalid request" response.
When I run the equivalent with python's "requests" it works (see below). The only difference that I could see is that the headers for vibed version have several "empty" Fields. I assumed that the empty fields would not be added when sending but I'm not sure...

Any ideas on what I'm missing?

Thanks,
Josh

// vibe.d's request headers
DictionaryList!(string, false, 12LU, false)(
[
    Field("Content-Type", "application/json"), 
    Field("Accept", "application/json"), 
    Field("Auth-Token", "FB355GG213234"), 
    Field("Content-Length", "42"), 
    Field("", ""), 
    Field("", ""), 
    Field("", ""), 
    Field("", ""), 
    Field("", ""), 
    Field("", ""), 
    Field("", ""), 
    Field("", "")
], 4, [])
// vibe.d - invalid request response
requestHTTP("https://some-rest.service.com/restapi”,
    (scope req) {
        req.method = HTTPMethod.POST;
        DictionaryList!(string, false, 12LU) headrs;
        headrs.addField("Content-Type", "application/json");
        headrs.addField("Accept", "application/json");
        headrs.addField(“Auth-Token", “FB355GG213234”);
        req.headers = headrs;
        req.writeJsonBody(some_json);
    },
    (scope res) {
        logInfo("Response: %d", res.statusCode);
        foreach (k, v; res.headers) {
            logInfo("Header: %s: %s", k, v);
        }

        logInfo("Response: %s", res.bodyReader.readAllUTF8());
    }
);
// python - works
headers = dict()
headers["Content-Type"] = "application/json"
headers["Accept"]       = "application/json"
headers[“Auth-Token”]   = "FB355GG213234"

r = requests.post("https://some-rest.service.com/restapi", headers=headers, json=some_json)

Re: getting invalid request with requestHTTP

also, there doesn't seem to be a way to print out the contents of the request's body for debugging... basically I want to make sure that the "json" that I "wroteJsonBody" to is formed correctly.

something like:
logInfo("%s", req.body);

thanks,
Josh