简体   繁体   中英

How can I make this API call from my Nodejs program?

A member of my team developed this API where you send some numeric values and it gives you back a probability. He deployed it in Heroku and sent me the task of connecting it with our backend, you can make the call from cmd like this:

curl -d "{\"Values\":[[value1,value 2,value 3,value 4,value 5]]}" -H "Content-Type: application/json" -X POST https://apibc1.herokuapp.com/predict

And it will work just like intended, but to be honest I don't know how to make this call in my server file, I'm trying to use the request package in Node but I keep getting the invalid URI error on my logs. An example of the API working from cmd: 在此处输入图像描述
And this is what happens when I make the same call in my server.js file:
在此处输入图像描述

If you have a working curl you can import it into postman and generate a working code sample for a lot of languages.

  1. Import the curl request

在此处输入图像描述

  1. Then click the code button on the right

在此处输入图像描述

  1. and select a language/framework option from the dropdown

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM