Reputation: 862
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
});
Upvotes: 0
Views: 552
Reputation: 2319
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;
}
Upvotes: 1