{"id":2073,"date":"2017-03-06T21:13:46","date_gmt":"2017-03-07T02:13:46","guid":{"rendered":"https:\/\/bitpost.com\/news\/?p=2073"},"modified":"2017-03-06T21:21:13","modified_gmt":"2017-03-07T02:21:13","slug":"redirection-best-practice-http-302","status":"publish","type":"post","link":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/","title":{"rendered":"Redirection best practice: HTTP 302"},"content":{"rendered":"<p>When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. \u00a0Research has indicated that the server should send the client an HTTP 302 page with the url. \u00a0Experimentation has shown that you can successfully set cookies. The cookie can be used to hold the url to re-redirect the user back to the original request after authenticating. Nice.<\/p>\n<p>Here&#8217;s the header to send from the server:<\/p>\n<pre><code>\r\n    const string cstr_HTML_302_HEADER1 = \"HTTP\/1.1 302 Moved Temporarily\\r\\nLocation: \";\r\n    const string cstr_HTML_HEADER2 = \"\\r\\n\\r\\n\";\r\n    \/\/ ....\r\n        string cookie_header = \"\\r\\n\";\r\n        cookie_header += \"Set-Cookie: .... \";\r\n        *response << cstr_HTML_302_HEADER1 << \"\/v1\/login.html\" << cookie_header << cstr_HTML_HEADER2;\r\n<\/code><\/pre>\n<p>The publicly available version of quick-http on <a href=\"https:\/\/github.com\/moodboom\/quick-http\">github<\/a> needs a refresh, hopefully I'll have some time soon to move a large set of new code there that uses <a href=\"https:\/\/github.com\/eidheim\/Simple-Web-Server\">Simple Web Server<\/a>, HTTP 302 redirects, user authentication, etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. \u00a0Research has indicated that the server should send the client an HTTP 302 page with the url. \u00a0Experimentation has shown that you can successfully set cookies. The cookie can be used to hold [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[233,10,9],"tags":[],"class_list":["post-2073","post","type-post","status-publish","format-standard","hentry","category-quick-http","category-tricks-tips-tools","category-websites"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. Research has indicated that the server should send the client an HTTP 302 page with the url. Experimentation has shown that you can successfully set cookies. The cookie can be used to hold\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"m\"\/>\n\t<meta name=\"keywords\" content=\"quick-http,tricks tips tools,websites\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"bitpost.com\/news | Note to self\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Redirection best practice: HTTP 302 | bitpost.com\/news\" \/>\n\t\t<meta property=\"og:description\" content=\"When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. Research has indicated that the server should send the client an HTTP 302 page with the url. Experimentation has shown that you can successfully set cookies. The cookie can be used to hold\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2017-03-07T02:13:46+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2017-03-07T02:21:13+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Redirection best practice: HTTP 302 | bitpost.com\/news\" \/>\n\t\t<meta name=\"twitter:description\" content=\"When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. Research has indicated that the server should send the client an HTTP 302 page with the url. Experimentation has shown that you can successfully set cookies. The cookie can be used to hold\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#article\",\"name\":\"Redirection best practice: HTTP 302 | bitpost.com\\\/news\",\"headline\":\"Redirection best practice: HTTP 302\",\"author\":{\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/author\\\/m\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#articleImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/884c1dbbf1027f261dbf20652687af7ad0030bfa71ff0ef56540938bdc70be2f?s=96&d=monsterid&r=pg\",\"width\":96,\"height\":96,\"caption\":\"m\"},\"datePublished\":\"2017-03-06T21:13:46-05:00\",\"dateModified\":\"2017-03-06T21:21:13-05:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#webpage\"},\"articleSection\":\"quick-http, Tricks Tips Tools, Websites\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/bitpost.com\\\/news\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/category\\\/projects\\\/#listItem\",\"name\":\"Projects\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/category\\\/projects\\\/#listItem\",\"position\":2,\"name\":\"Projects\",\"item\":\"https:\\\/\\\/bitpost.com\\\/news\\\/category\\\/projects\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/category\\\/projects\\\/websites\\\/#listItem\",\"name\":\"Websites\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/category\\\/projects\\\/websites\\\/#listItem\",\"position\":3,\"name\":\"Websites\",\"item\":\"https:\\\/\\\/bitpost.com\\\/news\\\/category\\\/projects\\\/websites\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#listItem\",\"name\":\"Redirection best practice: HTTP 302\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/category\\\/projects\\\/#listItem\",\"name\":\"Projects\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#listItem\",\"position\":4,\"name\":\"Redirection best practice: HTTP 302\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/category\\\/projects\\\/websites\\\/#listItem\",\"name\":\"Websites\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/#person\",\"name\":\"m\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/884c1dbbf1027f261dbf20652687af7ad0030bfa71ff0ef56540938bdc70be2f?s=96&d=monsterid&r=pg\",\"width\":96,\"height\":96,\"caption\":\"m\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/author\\\/m\\\/#author\",\"url\":\"https:\\\/\\\/bitpost.com\\\/news\\\/author\\\/m\\\/\",\"name\":\"m\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/884c1dbbf1027f261dbf20652687af7ad0030bfa71ff0ef56540938bdc70be2f?s=96&d=monsterid&r=pg\",\"width\":96,\"height\":96,\"caption\":\"m\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#webpage\",\"url\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/\",\"name\":\"Redirection best practice: HTTP 302 | bitpost.com\\\/news\",\"description\":\"When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. Research has indicated that the server should send the client an HTTP 302 page with the url. Experimentation has shown that you can successfully set cookies. The cookie can be used to hold\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/2017\\\/redirection-best-practice-http-302\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/author\\\/m\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/author\\\/m\\\/#author\"},\"datePublished\":\"2017-03-06T21:13:46-05:00\",\"dateModified\":\"2017-03-06T21:21:13-05:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/#website\",\"url\":\"https:\\\/\\\/bitpost.com\\\/news\\\/\",\"name\":\"bitpost.com\\\/news\",\"description\":\"Note to self\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/bitpost.com\\\/news\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Redirection best practice: HTTP 302 | bitpost.com\/news","description":"When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. Research has indicated that the server should send the client an HTTP 302 page with the url. Experimentation has shown that you can successfully set cookies. The cookie can be used to hold","canonical_url":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/","robots":"max-image-preview:large","keywords":"quick-http,tricks tips tools,websites","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#article","name":"Redirection best practice: HTTP 302 | bitpost.com\/news","headline":"Redirection best practice: HTTP 302","author":{"@id":"https:\/\/bitpost.com\/news\/author\/m\/#author"},"publisher":{"@id":"https:\/\/bitpost.com\/news\/#person"},"image":{"@type":"ImageObject","@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#articleImage","url":"https:\/\/secure.gravatar.com\/avatar\/884c1dbbf1027f261dbf20652687af7ad0030bfa71ff0ef56540938bdc70be2f?s=96&d=monsterid&r=pg","width":96,"height":96,"caption":"m"},"datePublished":"2017-03-06T21:13:46-05:00","dateModified":"2017-03-06T21:21:13-05:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#webpage"},"isPartOf":{"@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#webpage"},"articleSection":"quick-http, Tricks Tips Tools, Websites"},{"@type":"BreadcrumbList","@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news#listItem","position":1,"name":"Home","item":"https:\/\/bitpost.com\/news","nextItem":{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news\/category\/projects\/#listItem","name":"Projects"}},{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news\/category\/projects\/#listItem","position":2,"name":"Projects","item":"https:\/\/bitpost.com\/news\/category\/projects\/","nextItem":{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news\/category\/projects\/websites\/#listItem","name":"Websites"},"previousItem":{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news\/category\/projects\/websites\/#listItem","position":3,"name":"Websites","item":"https:\/\/bitpost.com\/news\/category\/projects\/websites\/","nextItem":{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#listItem","name":"Redirection best practice: HTTP 302"},"previousItem":{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news\/category\/projects\/#listItem","name":"Projects"}},{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#listItem","position":4,"name":"Redirection best practice: HTTP 302","previousItem":{"@type":"ListItem","@id":"https:\/\/bitpost.com\/news\/category\/projects\/websites\/#listItem","name":"Websites"}}]},{"@type":"Person","@id":"https:\/\/bitpost.com\/news\/#person","name":"m","image":{"@type":"ImageObject","@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/884c1dbbf1027f261dbf20652687af7ad0030bfa71ff0ef56540938bdc70be2f?s=96&d=monsterid&r=pg","width":96,"height":96,"caption":"m"}},{"@type":"Person","@id":"https:\/\/bitpost.com\/news\/author\/m\/#author","url":"https:\/\/bitpost.com\/news\/author\/m\/","name":"m","image":{"@type":"ImageObject","@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/884c1dbbf1027f261dbf20652687af7ad0030bfa71ff0ef56540938bdc70be2f?s=96&d=monsterid&r=pg","width":96,"height":96,"caption":"m"}},{"@type":"WebPage","@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#webpage","url":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/","name":"Redirection best practice: HTTP 302 | bitpost.com\/news","description":"When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. Research has indicated that the server should send the client an HTTP 302 page with the url. Experimentation has shown that you can successfully set cookies. The cookie can be used to hold","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/bitpost.com\/news\/#website"},"breadcrumb":{"@id":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/#breadcrumblist"},"author":{"@id":"https:\/\/bitpost.com\/news\/author\/m\/#author"},"creator":{"@id":"https:\/\/bitpost.com\/news\/author\/m\/#author"},"datePublished":"2017-03-06T21:13:46-05:00","dateModified":"2017-03-06T21:21:13-05:00"},{"@type":"WebSite","@id":"https:\/\/bitpost.com\/news\/#website","url":"https:\/\/bitpost.com\/news\/","name":"bitpost.com\/news","description":"Note to self","inLanguage":"en-US","publisher":{"@id":"https:\/\/bitpost.com\/news\/#person"}}]},"og:locale":"en_US","og:site_name":"bitpost.com\/news | Note to self","og:type":"article","og:title":"Redirection best practice: HTTP 302 | bitpost.com\/news","og:description":"When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. Research has indicated that the server should send the client an HTTP 302 page with the url. Experimentation has shown that you can successfully set cookies. The cookie can be used to hold","og:url":"https:\/\/bitpost.com\/news\/2017\/redirection-best-practice-http-302\/","article:published_time":"2017-03-07T02:13:46+00:00","article:modified_time":"2017-03-07T02:21:13+00:00","twitter:card":"summary","twitter:title":"Redirection best practice: HTTP 302 | bitpost.com\/news","twitter:description":"When an unauthenticated user accesses a protected resource of my API server, I want to immediately redirect them to the login page. Research has indicated that the server should send the client an HTTP 302 page with the url. Experimentation has shown that you can successfully set cookies. The cookie can be used to hold"},"aioseo_meta_data":{"post_id":"2073","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[],"defaultGraph":"","defaultPostTypeGraph":""},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-13 19:46:02","updated":"2025-08-17 19:15:28","seo_analyzer_scan_date":null},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9M11L-xr","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts\/2073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/comments?post=2073"}],"version-history":[{"count":5,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts\/2073\/revisions"}],"predecessor-version":[{"id":2078,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts\/2073\/revisions\/2078"}],"wp:attachment":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/media?parent=2073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/categories?post=2073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/tags?post=2073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}