Skip to main content
added 461 characters in body
Source Link
Victor F
  • 915
  • 17
  • 30

I need to redirect a user to http://www.someurl.com?id=2 using a POST method. Is it possible? If yes, then how?

Right now I have following and it forwards the POST data properly, but it removes the ?id=2:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.someurl.com?id=2"); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postData); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { Response.Write(reader.ReadToEnd()); } 

The reason I need both query string data -> ?id=2 and POST data is because I pass the query string to page in which javascript is going to be handling the query string data and .NET is going to work with data sent via POST method. The POST data that I am passing can be longer than maximum amount of characters that GET method allows, therefore I can't use only GET method... so, what are your suggestions?

More information: I am writing a routing page, which adds some custom information to query string and then routes all of the data, old and new further to some URL that was provided. This page should be able to redirect to our server as well as to someone's server and it doesn't need to know where it came from or where it goes, it just simply needs to keep the same POST, GET and HEADER information as well as additional information received at this step.

I need to redirect a user to http://www.someurl.com?id=2 using a POST method. Is it possible? If yes, then how?

Right now I have following and it forwards the POST data properly, but it removes the ?id=2:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.someurl.com?id=2"); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postData); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { Response.Write(reader.ReadToEnd()); } 

The reason I need both query string data -> ?id=2 and POST data is because I pass the query string to page in which javascript is going to be handling the query string data and .NET is going to work with data sent via POST method. The POST data that I am passing can be longer than maximum amount of characters that GET method allows, therefore I can't use only GET method... so, what are your suggestions?

I need to redirect a user to http://www.someurl.com?id=2 using a POST method. Is it possible? If yes, then how?

Right now I have following and it forwards the POST data properly, but it removes the ?id=2:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.someurl.com?id=2"); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postData); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { Response.Write(reader.ReadToEnd()); } 

The reason I need both query string data -> ?id=2 and POST data is because I pass the query string to page in which javascript is going to be handling the query string data and .NET is going to work with data sent via POST method. The POST data that I am passing can be longer than maximum amount of characters that GET method allows, therefore I can't use only GET method... so, what are your suggestions?

More information: I am writing a routing page, which adds some custom information to query string and then routes all of the data, old and new further to some URL that was provided. This page should be able to redirect to our server as well as to someone's server and it doesn't need to know where it came from or where it goes, it just simply needs to keep the same POST, GET and HEADER information as well as additional information received at this step.

deleted 77 characters in body; added 215 characters in body
Source Link
Victor F
  • 915
  • 17
  • 30

I need to redirect a user to http://www.someurl.com?id=2 using a POST method. Is it possible? If yes, then how?

Right now I have following and it forwards the POST data properly, but it removes the ?id=2:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(redirectUrl"http://www.someurl.com?id=2"); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; if using (urlReferrerStreamWriter !writer = nullnew StreamWriter(request.GetRequestStream())) { requestwriter.RefererWrite(postData); } HttpWebResponse response = urlReferrer(HttpWebResponse)request.ToStringGetResponse(); }  using (StreamWriterStreamReader writerreader = new StreamWriterStreamReader(requestresponse.GetRequestStreamGetResponseStream())) { writerResponse.Write(postDatareader.ReadToEnd()); } 

The reason I need both query string data -> ?id=2 and POST data is because I pass the query string to page in which javascript is going to be handling the query string data and .NET is going to work with data sent via POST method. The POST data that I am passing can be longer than maximum amount of characters that GET method allows, therefore I can't use only GET method... so, what are your suggestions?

I need to redirect a user to http://www.someurl.com?id=2 using a POST method. Is it possible? If yes, then how?

Right now I have following and it forwards the POST data properly, but it removes the ?id=2:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(redirectUrl); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; if (urlReferrer != null) { request.Referer = urlReferrer.ToString(); }  using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postData); } 

The reason I need both query string data -> ?id=2 and POST data is because I pass the query string to page in which javascript is going to be handling the query string data and .NET is going to work with data sent via POST method. The POST data that I am passing can be longer than maximum amount of characters that GET method allows, therefore I can't use only GET method... so, what are your suggestions?

I need to redirect a user to http://www.someurl.com?id=2 using a POST method. Is it possible? If yes, then how?

Right now I have following and it forwards the POST data properly, but it removes the ?id=2:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.someurl.com?id=2"); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length;  using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(postData); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { Response.Write(reader.ReadToEnd()); } 

The reason I need both query string data -> ?id=2 and POST data is because I pass the query string to page in which javascript is going to be handling the query string data and .NET is going to work with data sent via POST method. The POST data that I am passing can be longer than maximum amount of characters that GET method allows, therefore I can't use only GET method... so, what are your suggestions?

Sacrificed the "httpwebresponse" tag in favor of "c#". Should give it better visibility.
Link
zneak
  • 139.1k
  • 48
  • 270
  • 342
Source Link
Victor F
  • 915
  • 17
  • 30
Loading