0

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
                    });
Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
Syed Waqas
  • 862
  • 2
  • 9
  • 29

1 Answers1

1

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;

}

Ratna
  • 2,289
  • 3
  • 26
  • 50
  • it does not work, I think there is something wrong the way we are passing the params, its a json service by the way – Syed Waqas Nov 07 '13 at 12:37