Replies: 2 comments 1 reply
-
So let me recap: Sure I can add it! If I'm honest with you I dont know why I took the first approach :D Could you give me an example using https://postman-echo.com/post so I can see the shape of the received data? |
Beta Was this translation helpful? Give feedback.
-
Great, thanks! Example script: var url = "https://postman-echo.com/post";
var respText = ui.addText("", 0, 0.3);
// this data could be any plain javascript object, my actual use case is POSTing location data
// to an api so that's what I've used here
const data = {client: "phone", lat: 20.5438, lon: 50.263, speed: 15, alt: 23};
const sendDataCurrent = (someData) => {
network.httpRequest({
method: 'POST',
url: url,
data: [
{ 'name': 'data', 'content': JSON.stringify(data), 'type': 'json' }, // current usage
]
}).onResponse(function (e) {
console.log(e.status, e.response);
respText.text("" + e.status + "\r\n" + e.response);
})
}
var btn = ui.addButton('POST data', 0.05, 0.1, 0.5, 0.1).onClick(function () {
sendDataCurrent(data);
}) The postman data I get back currently is: {"args":{},"data":{},"files":{},"form":{"data":"{\"client\":\"phone\",\"lat\":20.5438,\"lon\":50.263,\"speed\":15,\"alt\":23}"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5fe3b692-7d97e0d008dfd0a8764c6cef","content-length":"216","content-type":"multipart/form-data; boundary=85fefd15-2b9b-4dee-8d01-57f87b32260b","accept-encoding":"gzip","user-agent":"okhttp/3.10.0"},"json":null,"url":"https://postman-echo.com/post"} I would expect {"args":{},"data":{"client":"phone","lat":20.5438,"lon":50.263,"speed":15,"alt":23},"files":{},"form":{},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5fe3b7a0-7ff566134d45db541a13c623","content-length":"65","accept":"*/*","accept-encoding":"deflate, gzip","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36","content-type":"application/json"},"json":{"client":"phone","lat":20.5438,"lon":50.263,"speed":15,"alt":23},"url":"https://postman-echo.com/post"} Edit: I used reqbin to generate the correct one, so there is some extra header data in there too which obviously I wouldn't expect |
Beta Was this translation helpful? Give feedback.
-
Hi @victordiaz! With the updates to network requests in 1.3.1 I'm wondering if it's possible to POST a plain JSON body to an endpoint?
I have an api which requires JSON-only body to add data to a database, but using something like
results in the following body POSTed:
Is it possible to have just the plain JSON body? If not, I can open an issue as a Feature Request?
Beta Was this translation helpful? Give feedback.
All reactions