Question

Here i do not want to wait for response from server because i do not care about response for these httpwebrequest.

is it ok? or will it affect system in future?

HttpWebRequest PostRequest = (HttpWebRequest)WebRequest.Create(PostUrl);
        PostRequest.ContentType = PostContentType;
        PostRequest.Method = "POST";
        byte[] bytes = Encoding.ASCII.GetBytes(DataUrl);            
        try
        {
            PostRequest.ContentLength = bytes.Length;
            using (Stream webpageStream = PostRequest.GetRequestStream())
            {
                webpageStream.Write(bytes, 0, bytes.Length);
            }
        }
        catch (Exception ex)
        {
            //
        }

Thanks

Was it helpful?

Solution

You can call asynchronous BeginGetRequestStream() and then handle response data when it completes. If you don't need response data, then you can just ignore it, but you might be interested in obtaining a response status code to check if your request succeeded.

OTHER TIPS

yeah just dont forget to add these lines

  webpageStream.Flush();
  webpageStream.Close();

yest the befor this answer is so true , remove this codes:

var response = (HttpWebResponse)request.GetResponse();

var responseString = new SreamReader(response.GetResponseStream()).ReadToEnd();

and add the flowing code on using stream like this after stream.write:

stream.Flush();
stream.Close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top