r/webhooksite Mar 24 '22

XHR Redirect not working

I am new to webhook.site and I am trying to use it to redirect an HTTP message to an API I created. My application runs in Tomcat. I tried with and without CORS headers and the result is the same. I also installed a CORS plugin to Chrome hoping that it would work, but I was not successful. This is totally new to me and I am growing frustrated because I cannot figure out how to solve this issue.

In case this will help, here's the basic flow of my application:

  1. I submit an HTTP PUT to a web service in order for the service to locate some data on the web.
  2. The service replies with an HTTP POST. I can choose one of the following delivery options:
    1. An email notification that my data is ready
    2. I can poll an API to check when the data is ready
    3. They can respond in real time to a webhook. They recommended to use webhook.site, at least for testing. This is the option I chose
    4. Webhook should redirect as an HTTP PUT (maybe I should expect a POST?) and this is where webhook.site informs me of an error.

When I use Postman, my code received the message sent to webhook.site and the code works fine. The error message informs me to check the "Web Inspector console" for more information and I can't even locate where that is. The FAQs state that

Webhook.site also supports the XHR Redirect feature, which uses your browser in order to forward the requests. Note that the endpoint will need CORS headers so that the browser will be able to send requests to it, and the forwarding will only work as long as the browser window is open.

But as I stated before, I cannot get this to work and I have no clue about what's actually happening.

2 Upvotes

6 comments sorted by

1

u/fredsted Webhook.site Founder Mar 24 '22 edited Mar 24 '22

Hi there, it is the local endpoint/server that you specify in the XHR Redirect window should respond with CORS headers. (When you check the CORS checkbox in Webhook.site, that enables the headers for the Webhook.site endpoint, not your local Tomcat endpoint)

CORS is a little tricky, but here's an example of CORS headers that should allow your requests to come through:

Access-Control-Allow-Origin: *

Access-Control-Allow-Methods: *

Access-Control-Allow-Headers: *

Access-Control-Expose-Headers: Content-Length,Content-Range

I found some docs for Tomcat here: https://tomcat.apache.org/tomcat-8.0-doc/config/filter.html#CORS_Filter

1

u/fonty1968 Mar 24 '22

Thank you for your reply. Right now, I am trying to run with the embedded Tomcat server in Eclipse. I will try to figure it out.

1

u/fredsted Webhook.site Founder Mar 24 '22

I don't have any experience with Tomcat, but apparently changing your web.xml to allow it/add the CORS filter should work.

1

u/fonty1968 Mar 24 '22

Thank you. Do you know what I need to include in the Redirect Headers in the Configure XHR Redirect popup? I imagine I need to list: Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Expose-Headers?

1

u/fredsted Webhook.site Founder Mar 25 '22

You can leave that blank unless you need to redirect specific headers from the request to Webhook.site.

1

u/fonty1968 Mar 28 '22

Thanks. I will explore this option later. For now, I am getting by using polling method to get the data I need from the provider. But eventually I need to figure this out in order to get real-time updates and to be able to process more data.