简体   繁体   中英

What is the alternative to JQuery post in ASP.NET C#

What is the alternative to Jquery post in asp.net C#

var scrapyd_url = 'http://www.domain.com/';
var project_name = 'xxxx';
var spider_name = 'yyy';

$.post(scrapyd_url + 'schedule.json', {
                        project: project_name,
                        spider: spider_name
                    });

I think you will like webrequest and webresponse class amde for this purpose only @ http://msdn.microsoft.com/en-us/library/system.net.webrequest%28v=vs.110%29.aspx

An example (Copied)

  public string SendPost(string url, string postData)
{
string webpageContent = string.Empty;

try
{
    byte[] byteArray = Encoding.UTF8.GetBytes(postData);

    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
    webRequest.Method = "POST";
    webRequest.ContentType = "application/x-www-form-urlencoded";
    webRequest.ContentLength = byteArray.Length;

    using (Stream webpageStream = webRequest.GetRequestStream())
    {
        webpageStream.Write(byteArray, 0, byteArray.Length);
    }

    using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
    {
        using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
        {
            webpageContent = reader.ReadToEnd();
        }
    }
}
catch (Exception ex)
{
    throw;
}

return webpageContent;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM