GK1667
GK1667

Reputation: 1362

Contact API directly from URL in browser

I am trying to understand how POST and/or GET methods work in terms of the actual browser.

I am attempting to contact an API which requires API key, method you wish to use on their side, and an IP address at the minimum.

My original idea was to do something like this:

I feel like I'm on the right track, it does something and gets an error as opposed to telling me the page does not exist. I'm expecting either JSON or XML in response as the API supports both but instead I get this error:

This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.

Upon studying the documentation of the API more, I found something saying that methods are called using HTML form application/x-www-form-urlencoded and the resuource models are given as form elements.

I tried researching what that means to see what the problem was and found this site http://www.w3.org/TR/xforms11/ but I'm still unclear.

Ideas?

Upvotes: 1

Views: 545

Answers (1)

zeh
zeh

Reputation: 10669

It seems to mean that the application is expecting a POST method but you're doing a request with a GET method (when you use the querystrings).

Since you can't just do browser requests using POST using the address bar, you may need to:

  • Construct a simple JS function that does a xmlhttprequest request using that method instead, and running it from the console;
  • Create a simple HTML page that automates the above process, allowing you do make POST calls;
  • Using CURL instead, which is a great tool for testing those kinds of requests.

Upvotes: 1

Related Questions