HttpWebRequest with POST and GET at the same time

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

I am following him now and it is correctly transmitting the POST data, but is it deleting the identifier? 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());
}

Do I need query string data →? id = 2 and POST data, because I pass the request string to the page in which javascript will process the data of the query string, and .NET will work with the data sent by the POST method. The POST data I pass may be longer than the maximum number of characters that the GET method allows, so I can’t use only the GET method ... so what are your suggestions?

: , , , , URL-, . , - , , , POST, GET HEADER, , .

+3
8

, Javascript Codebehind. , , -, :

    var strForm = new StringBuilder();
    strForm.Append("<form id=\"" + formId + "\" name=\"" + formId + "\" action=\"" + url + queryString +"\" method=\"POST\">");
    foreach (string key in data)
    {
        strForm.Append("<input type=\"hidden\" name=\"" + key + "\" value=\"" + data[key].Replace("\"", "&quot;") + "\">");
    }
    strForm.Append("</form>");

, , javascript, , .

    var strScript = new StringBuilder();
    strScript.Append("<script language='javascript'>");
    strScript.Append("var v" + formId + " = document." + formId + ";");
    strScript.Append("v" + formId + ".submit();");
    strScript.Append("</script>");
    strForm.Append("</form>");

, , , - URL- , ... POST, , , POST... , POST GET.

, - =)

0

. , POST GET.

, , Javascript, ...

<input type="hidden" value="id=2,foo=bar" disabled="disabled" />

.

. , POST, ;)

+2

, , , postData id, querystring.

, URL-.

, request.querystring postdata.

+1

, , , . javascript, URL . , , POST GET.

+1

, POST . ( ), , ?

0
0

, POST. , #, id - :

<script type="text/javascript">
  id = <%=request_id%> 
</script>

, javascript onload(), .

0

, , - POST. , ? , , .

, POST script # 1, - script2.aspx? id = 234, 234 . 2 Javascript .

, - . . . ( !)

0
source

Source: https://habr.com/ru/post/1772533/


All Articles