var req ={
"request": {
"header": {
"username": "name",
"password": "password"
},
"body": {
"shape":"round"
}
}
};
request.post(
{url:'posturl',
body: JSON.stringify(req),
headers: { "content-type": "application/x-www-form-urlencoded"}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
Desidero inviare corpo di richiesta grezza in variabile req. Funziona su postman ma nel nodo js non sono in grado di inviare il json raw come corpo della richiesta per la richiesta post.nodo js invia richiesta post con corpo di richiesta raw
Qual è l'errore? Potrebbe il tuo "content-type": "application/x-www-form-urlencoded" 'essere errato, dal momento che stai inviando JSON? Dovrebbe essere 'application/json'. –
POST /HTTP/JSON/Prices/GetPriceSheet.aspx HTTP/1.1 Host : host.com Content-Type: application/x-www-form-urlencoded Cache-Control: no-cache { "richiesta": {"header": {"username": "nome", "password": "pw"}, "body": {"shape": "round"}}} Questa è l'anteprima della richiesta che sta funzionando su postman. Quindi ho bisogno di x-www-form-urlencoded nell'header ma anche di inviare dati raw json. L'errore che sto ottenendo è formato errato dal servizio di riposo. –