Can you spot the bug in the following code? (Hint: it compiles and no run-time errors)
It’s not so obvious until I expose the code that preceded it. So let’s try this again (with more information). Can you spot the bug in the following code?
The issue with the second call to
apex_web_service.make_rest_request is that it will use the request headers that were set for the first call (to
a-differnt-url.com). If the second web service (
someurl.com) doesn’t want/need/expect that header it can cause some unintended issues and may result in an invalid RESTful call.
To get around this simply clear the request headers each time before setting them / calling
apex_web_service.make_rest_request. You can do this by calling
apex_web_service.g_request_headers.delete(); The following code is the correct way to run the previous example: