How To Figure Out The Required Headers For A Java REST Call?
When testing with the jsonplaceholder.typicode.com site java code does not need to set any headers. Reading the json from a URLConnection
works fine. However other http endpoints will return a 403 Forbidden
unless a HttpURLConnection
is used and the User-Agent
request property is set.
Is there a way other than trial and error to figure out the required headers for a given http endpoint?
Answer
There's nothing in the HTTP protocol that allows you to observe what headers a particular server is expecting. You send a request, and the server sends a response, that's all. (A nice server may, of course, choose to embed a helpful error message in its response.)
So the literal answer to your question is: no, there's no way to determine this beyond trial and error (unless you have access to documentation and/or source code).
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM