[question] howto disable redirect?
Hi
I GET a url that redirects (302) to a new url. cpprestsdk automatically redirects to the new url. In this case that's not what I want. I want to disable redirection, so that I can get at the http response header of the original url. (This header has important Set-Cookie information. I need to store this cookie in my application, so that I can use this cookie later for other GET calls)
How do I do this?
[bump]
[bump]
You will need to use http_client_config::set_nativehandle_options() to set the WINHTTP_OPTION_REDIRECT_POLICY:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384066(v=vs.85).aspx
I was able to disable redirects on windows by using the code shown below, does anyone know how to achieve the same on Linux?
void CallbackFunc(native_handle handle) {
// disable auto redirects
DWORD dwOptionValue = WINHTTP_DISABLE_REDIRECTS;
BOOL sts = WinHttpSetOption(handle, WINHTTP_OPTION_DISABLE_FEATURE, &dwOptionValue, sizeof(dwOptionValue));
if (!sts) {
std::cerr << "WINHTTP_DISABLE_REDIRECTS failed.\n";
}
}
// later create http_client like shown below
http_client_config config;
config.set_nativehandle_options(CallbackFunc);
http_client client(U("http://some_url/"), config);
@zwaheed-rms, I don't believe that redirects are implemented in the asio-based http client which is used on Linux.
Necro-posting just to show a more concise way to do it that worked for me:
http_client_config clientConfig;
clientConfig.set_nativehandle_options([&](web::http::client::native_handle nativeHandle) {
// Disable auto redirects
DWORD dwOptionValue = WINHTTP_DISABLE_REDIRECTS;
BOOL sts = WinHttpSetOption(nativeHandle, WINHTTP_OPTION_DISABLE_FEATURE, &dwOptionValue, sizeof(dwOptionValue));
if (!sts) {
std::cerr << "WINHTTP_DISABLE_REDIRECTS failed.\n";
}
});