Brushless Motor Movement Panel icon Brushless Motor Movement Panel — Control brushless motor controllers (hoverboard-style) via EZ-B: configure direction, speed and optional brake ports for DIY robot movement. Try it →
Indonesia
LinkedIn Twitter YouTube GitHub
Asked — Edited
Resolved Resolved by DJ Sures!
1 Participant
How to send JSON & set header request on Net.hTTPPost() method?

How To Send JSON & Set Header Request On Net.Httppost() Method?

Hi everyone, I'm using Net.hTTPPost(url, postData) method on ARC script (JavaScript). I've just realized that this method only send the body payload request as x-www-form-urlencoded. My problems are:

  1. How to send JSON data? I've tried JSON.stringify() but it didn't work as my expectation.
  2. How to set its header request? Here I attach my basic code to make a simple POST request to JSON Placeholder Fake API. I'm curious how to send JSON & how to set its header request.
var resPost = Net.hTTPPost(
   "https://jsonplaceholder.typicode.com/posts";,
   'name=Andy&age=20'
)
print(resPost)

resPost = JSON.parse(resPost)
print(resPost.name)
print(resPost.age)

Run this code & you will see the following log in console:

> {
  "name": "Andy",
  "age": "20",
  "id": 101
}
> Andy
> 20

Hope someone in this community can help me solve this problem. Thanks in advance.



Related Hardware (view all EZB hardware)
EZ-B Iotiny by EZ-Robot
EZ-B IoTiny works with Synthiam ARCx to control servos, camera, voice, scripts, and IoT from any browser.
Wi-Fi
Servos 8
Camera
Audio
UART None (transmit-only serial on digital ports)
I2C
ADC 2
Digital 8

Related Robot Skills (view all robot skills)
Script by Synthiam
Multi-language ARC Script: build, run and debug Blockly, JavaScript, EZ-Script or Python with Intellisense, run/save/load and Roboscratch support
Real-time EZ-Script console for ARC: enter and execute single-line commands, view output, clear display, and recall history with UP/DOWN.

ARC Pro

Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#9  

Great! there’s so much power by creating custom robot skills. And the ARC framework exposes methods that make it so easy:)