0

asp.net C#中Jquery post的替代方法是什么

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
                    });
4

1 回答 1

1

我想你会喜欢 webrequest 和 webresponse 类 amde 仅用于此目的@ http://msdn.microsoft.com/en-us/library/system.net.webrequest%28v=vs.110%29.aspx

一个例子(复制)

  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;

}

于 2013-11-07T12:24:57.780 回答