TransWikia.com

Making comparisons in a HTTPS GET request in node js

Stack Overflow Asked by thor_ on December 24, 2020

const https = require("https");
const opts = {
    hostname: "nvdbapiles-v3.atlas.vegvesen.no",
    port: 443,
    path: "/vegobjekter/60.json?egenskap=egenskap(10278)>=2018",
    method: "GET",
    headers: {
        "user-agent": "Testagent",
        "Accept": "application/vnd.vegvesen.nvdb-v3-rev1+json"
    }
};


let dataString = "";
const req = https.request(opts, async res => {
    console.log(res.statusCode);
    res.setEncoding("utf-8");
    res.on("data", data => {
        dataString += data;
    });

    res.on("close", async () => {
        console.log(dataString);
    });
});

I want to get all bridges built after 2018 from a database. This works in browser but breaks because of the ">" when making a GET request. It returns HTTP Status 400 – Bad Request

java.lang.IllegalArgumentException: Invalid character found in the request target [/vegobjekter/60.json?egenskap=egenskap(10278)>=2018]. The valid characters are defined in RFC 7230 and RFC 3986

What is the correct way of making comparisons in a GET request?

Using node version 14.13.0

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP