A
A
AcidBat2016-02-10 16:20:26
ASP.NET
AcidBat, 2016-02-10 16:20:26

How to send a client to a page along with a POST request?

There was a need to send a POST request not from the client, but from the server. The problem is that I do not need to receive a response from the server to the POST request, but send the user along with this request there.
Can this be implemented somehow?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VZVZ, 2016-02-10
@VZVZ

Well, let a POST request be sent on the page (at least with JS, at least server-side - at least with System.Net), and you forward the user to that page. Problems?

P
Peter, 2016-02-10
@petermzg

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
webRequest.Method = "POST";
webRequest.ContentType = "application/json";
webRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
webRequest.ServicePoint.Expect100Continue = false;
if (headers != null)
     webRequest.Headers.Add(headers);

using (Stream stream = webRequest.GetRequestStream())
    using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
          writer.Write(json.ToString());

JsonClass jsonAnswer;
using (WebResponse response = webRequest.GetResponse())
       using (Stream responseStream = response.GetResponseStream())
            using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
            {
                        Json parser = new Json();
                        jsonAnswer = (JsonClass)parser.Parse(reader.ReadToEnd());
             }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question