Background
Break News
How to add local font to Tailwind Css and NextJS? - Tutorial Design Pattern? - Blockchain Technology, How to create own Bitcoin virtual currency - Zustand mordern management state - Design Pattern - Flyweight Pattern? - Docker Full training Topic

[Tips] GetResponseStream Reading Response From URL using HTTP Web Request C#

Monday 11 April 2016
|
Read: Completed in minutes

[Tips] GetResponseStream Reading Response From URL using HTTP Web Request C#

If you have problem for your httpwebrequest and httpwebresponse, please view below tips, maybe can help you so much ^^
This below function will be show you how to using https web request in C# with GET and POST method to get data on the server.

GetResponseStream Reading Response From URL using HTTP Web Request C#









πŸ‘‰You can download full source code from
Post Method:
See the below code:


static private string getResponeseString(string user, string pw)
{
   var request = (HttpWebRequest)WebRequest.Create
                  ("https://idol.talktv.vn/login/check");

    var postData = "act=frm&username=" + user;
    postData += "&password=" + pw;
    var data = Encoding.ASCII.GetBytes(postData);

    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = data.Length;

    using (var stream = request.GetRequestStream())
    {
 stream.Write(data, 0, data.Length);
    }

    var response = (HttpWebResponse)request.GetResponse();
    return new StreamReader(response.GetResponseStream()).ReadToEnd();
}

Get Method:
You can have any below function for do it!

The first function:

public static XmlDocument getXMLDocumentFromXMLTemplate(string inURL)
{
        //Declare an HTTP-specific implementation of the WebRequest class.
 HttpWebRequest myHttpWebRequest = null;     

        //Declare an HTTP-specific implementation of the WebResponse class
 HttpWebResponse myHttpWebResponse = null;

        //Declare XMLResponse document   
 XmlDocument myXMLDocument = null;  

        //Declare XMLReader         
 XmlTextReader myXMLReader = null;           

 try
 {
  //Create Request
  myHttpWebRequest = (HttpWebRequest) HttpWebRequest.Create(inURL);
  myHttpWebRequest.Method = "GET";
  myHttpWebRequest.ContentType = "text/xml; encoding='utf-8'";

  //Get Response
  myHttpWebResponse = 
                       (HttpWebResponse)myHttpWebRequest.GetResponse();

  // Process the data. Now load the XML Document
  myXMLDocument = new XmlDocument();

  //Load response stream into XMLReader
  myXMLReader = new XmlTextReader(
                                myHttpWebResponse.GetResponseStream());
  myXMLDocument.Load(myXMLReader);
 }
 catch (Exception myException)
 {
  throw new Exception("Error Occurred in 
                        AuditAdapter.getXMLDocumentFromXMLTemplate()", myException);
 }
 finally
 {
  myHttpWebRequest = null;
  myHttpWebResponse = null;
  myXMLReader = null;
 }
 return myXMLDocument;
} 

The second function:

private bool getResponeseString(string user)
{
    string sURL = "https://id.zing.vn/v2/uname-suggestion?username=" + 
                                            user + "&cb=zmCore.js998139";

    WebRequest request;
    request = WebRequest.Create(sURL);

    WebProxy myProxy = new WebProxy("myproxy", 80);
    myProxy.BypassProxyOnLocal = true;

    Stream objStream;
    objStream = request.GetResponse().GetResponseStream();
    StreamReader objReader = new StreamReader(objStream);

    return objReader.ReadToEnd();
}


πŸ‘‰You can download full source code from
If you want to Add customer Header in HttpWebRequest, you can view example from here

How about topic GetResponseStream Reading Response From URL using HTTP Web Request C# . If you have any feedback or questions, please leave your comment we can discuss about it!

Wishes you have more healthy and have a nice day!
Regards!
Webzone tech tips Zidane



πŸ™‡πŸΌπŸ™‡πŸΌ We Appreciate Your Comments and Suggestions - Webzone, all things Tech Tips web development
Popular Webzone Tech Tips topic maybe you will be like it - by Webzone Tech Tips - Zidane
As a student, I found Blogspot very useful when I joined in 2014. I have been a developer for years . To give back and share what I learned, I started Webzone, a blog with tech tips. You can also search for tech tips zidane on Google and find my helpful posts. Love you all,

I am glad you visited my blog. I hope you find it useful for learning tech tips and webzone tricks. If you have any technical issues, feel free to browse my posts and see if they can help you solve them. You can also leave a comment or contact me if you need more assistance. Here is my blog address: https://learn-tech-tips.blogspot.com.

My blog where I share my passion for web development, webzone design, and tech tips. You will find tutorials on how to build websites from scratch, using hot trends frameworks like nestjs, nextjs, cakephp, devops, docker, and more. You will also learn how to fix common bugs on development, like a mini stackoverflow. Plus, you will discover how to easily learn programming languages such as PHP (CAKEPHP, LARAVEL), C#, C++, Web(HTML, CSS, javascript), and other useful things like Office (Excel, Photoshop). I hope you enjoy my blog and find it helpful for your projects. :)

Thanks and Best Regards!
Follow me on Tiktok @learntechtips and send me a direct message. I will be happy to chat with you.
Webzone - Zidane (huuvi168@gmail.com)
I'm developer, I like code, I like to learn new technology and want to be friend with people for learn each other
I'm a developer who loves coding, learning new technologies, and making friends with people who share the same passion. I have been a full stack developer since 2015, with more than years of experience in web development.
Copyright @2022(November) Version 1.0.0 - By Webzone, all things Tech Tips for Web Development Zidane
https://learn-tech-tips.blogspot.com