What do you mean by “handle this in ServiceStack”? Is this POST to a ServiceStack Service? If this request is to a 3rd Party API (i.e. non ServiceStack Service) you can use HTTP Utils to send HTTP requests.
HTTP Utils is a just thin abstraction over .NET Framework’s HttpWebRequest, you can use the optional requestFilter: available in each API to modify details of the Web Request like whether it should AllowAutoRedirect, e.g:
std::string ComputeMethodForRedirect(const std::string& method,
int http_status_code) {
// For 303 redirects, all request methods except HEAD are converted to GET,
// as per the latest httpbis draft. The draft also allows POST requests to
// be converted to GETs when following 301/302 redirects, for historical
// reasons. Most major browsers do this and so shall we. Both RFC 2616 and
// the httpbis draft say to prompt the user to confirm the generation of new
// requests, other than GET and HEAD requests, but IE omits these prompts and
// so shall we.
// See:
// https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#section-7.3
if ((http_status_code == 303 && method != "HEAD") ||
((http_status_code == 301 || http_status_code == 302) &&
method == "POST")) {
return "GET";
}
return method;
}
Please read the available docs and use the API yourself first to make sure the default behavior doesn’t do what you want, if it doesn’t you can use the requestFitler to modify the HTTP request, e.g. set req.AllowAutoRedirect = false so it doesn’t follow redirects then you can inspect the Response Headers with responseFilter:, e.g. grab the Location Header and use it to send the new request that you want.
Thank you. How would you interpret the location // - see below the response?
The facts I know are:
in a browser, the identical POST returns a sensible value
the identical POST in RestSharp returns location //, and even with RestSharp’s FollowRedirects, RestSharp does not do anything. So I think the most likely explanation is the required transition to GET. However, I was unable to get this work in RestSharp.
I will try tomorrow with SS and will revert if it does not work.
I suspect a Location value of // is a Server API error. A url starting with / is relative to the domain if the POST was to http://example.org/v1/myapi a Location of / would redirect to http://example.org/ so a // I’d expect to mean a redirect to http://example.org// which doesn’t look intentional.