title: How to handle status 302 redirect in c# httpwebreqest ASP.NET
body: <p>Here is my code:</p>
  
  <pre><code>   @{
          //string postString = "parameter=value";
          const string contentType = "application/x-www-form-urlencoded";
          System.Net.ServicePointManager.Expect100Continue = false;
  
          CookieContainer cookies = new CookieContainer();
          HttpWebRequest webRequest = WebRequest.Create("http://somehost:8080/myApp") as HttpWebRequest;
          webRequest.Method = "POST";
          webRequest.AllowAutoRedirect = false;
          webRequest.ContentType = contentType;
          webRequest.CookieContainer = cookies;
          webRequest.ContentLength = postString.Length;
          webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
          webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  
          StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
          requestWriter.Write(postString);
          requestWriter.Close();
  
          HttpWebResponse resp = webRequest.GetResponse() as HttpWebResponse;
          string location = resp.Headers["Location"];
          Response.Redirect(location);
      }
  </code></pre>
  
  <p>response from <code>http://somehost:8080/myApp</code> is 302 redirect to some other domain. If I use <code>webRequest.AllowAutoRedirect = true;</code> and write response (<code>Response.Write(StreamReader(resp.GetResponseStream()).ReadToEnd())</code>), resulting html is not shown correctly because resources with relative links could not be resolved.</p>
  
  <p>So, I came up with this solution but I feel that it's not correct. It seems to me that my solution is sort of 'hackaround'.</p>
  
  <p>Is there better solution?</p>