Sending a POST request to API with localhost

Roger

I am sending an image to an API using my localhost address but for some reason it doesn't identify the image. It works fine if I use links on google. The code looks something like this:

unirest.post(requestString)
   .header("X-RapidAPI-Key", API_KEY)
   .field("urls", "http://localhost:4000/uploads/1570544614486-test.jpg")
   .field("album", ALBUM_NAME)
   .field("albumkey", ALBUM_KEY)
   .field("entryid", entryId)
   .end(result => {
       console.log(result.body);
});

I believe this will work once on a domain but I need it to work now for testing. How can I make this work using my localhost?

esqew

You haven't exactly specified what API you're reaching out to, so your mileage may vary with different APIs.

However, based on your error message, I've determined you're trying to leverage the Lambda Face Recognition and Face Detection API via RapidAPI. This (linked) docs for this web service clearly show that the urls parameter you're attempting to use with your localhost URL above is actually meant to hold a comma-separated set of URLs to publicly-accessible image files. The remote API can't possibly resolve localhost in this context, because (a) it can't possibly have any idea what IP localhost should refer to, and (b) it's highly likely that your localhost here doesn't respond to HTTP requests from the broader Internet.

Instead, modify your request to use the files parameter (type binary) to upload the raw binary data for your image(s).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related