1

I have the following situation:

The browser does a POST with a Json payload to my server endpoint

My server processes the data and then issues a redirect to a new location

The browser does the redirect, but it does it with the same headers as the original post which mean it arrives at my endpint such that my endpoint thinks it is a json request.

-> I want the redirect to arrive at my server as a standard text/html request.

Is it possible to control the headers that the redirect uses so that the Get request arrives with text/html Accept headers?

Here are some snippets from fiddler to highlight what I am talking about:

Initial POST, json payload:

POST /App/Client/Index HTTP/1.1
Accept: application/json, text/plain, */*
X-Requested-With: XMLHttpRequest

The response:

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2App%2fClient%2f%2fSingleEntity%3fentityId%3df859a6ca-dbcf-49cf-8de0-3888b7011815">here</a>.</h2>
</body></html>

The subsequest GET request from the Redirect:

GET /App/Client/SingleEntity?entityId=f859a6ca-dbcf-49cf-8de0-3888b7011815 HTTP/1.1
Accept: application/json, text/plain, */*
X-Requested-With: XMLHttpRequest
zadam
  • 2,416
  • 2
  • 23
  • 32

1 Answers1

0

I had a similar requirement. My solution was to not send a redirect, but a "200 OK" with the following JSON:

{"url": "http://example.com/redirect/to/some/resource"}

The client used the URL and redirected via Javascript, i.e. location.href = data.url. It might not be the answer you're looking for but it solves your problem...

See also: How to manage a redirect request after a jQuery Ajax call

Community
  • 1
  • 1
awendt
  • 13,195
  • 5
  • 48
  • 66