Create Web Request in C# using asp.net


Name Space 


using System.Collections.Specialized;
using System.Net;

using System.IO;

 public string Post_Method(string uri, string command)
    {
        WebRequest req = null;
        WebResponse rsp = null;
        string tempReply = "";
        try
        {
            req = WebRequest.Create(uri);
            req.Method = "post";
            req.ContentType = "application/x-www-form-urlencoded";
            StreamWriter writer = new StreamWriter(req.GetRequestStream());
            writer.Write(command);
            writer.Close();

            // Send the data to the webserver
            rsp = req.GetResponse();

            StreamReader reader = new StreamReader(rsp.GetResponseStream());
            tempReply = reader.ReadToEnd().ToString();
            tempReply = tempReply.Trim();
        }
        catch (Exception ex)
        {
            tempReply = "01";
        }
        return tempReply;
    }
        

Comments

Popular posts from this blog

Multipart/form-data using basic auth

How to Capture image of HTML5 camera in asp.net

Simple API that receive MultipartData File with parameter in ASP.net Web API