日期:2014-05-17  浏览次数:20355 次

asp.net发送post数据
如下有一个接口
 http://api.vs128.com/ajax/api.ashx
它只接收post数据的id,

以下是 asp发送的post数据

set http = Server.CreateObject("MSXML2.XMLHTTP")
'以异步方式发送数据
http.open "POST","http://api.vs128.com/ajax/api.ashx",false
http.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
http.send("id=1")
'Result为api接口的响应信息
'responseBody: 结果返回为无符号整数数组。
'responseStream: 结果返回为IStream流。
'responseText : 结果返回为字符串。
'responseXML: 结果返回为XML格式数据。

Result = http.ResponseText
set http = Nothing


请问asp.net 如果发送post数据
asp.net发送post数据 asp.net

------解决方案--------------------
WebClient.UploadString("id=1")   详情msdn
------解决方案--------------------
		WebClient webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string s = webClient.UploadString("http://api.vs128.com/ajax/api.ashx", "POST", "id=1");
Response.Write(s);

------解决方案--------------------
在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求

/// <summary>  
        /// 创建POST方式的HTTP请求  
        /// </summary>  
        /// <param name="url">请求的URL</param>  
        /// <param name="parameters">随同请求POST的参数名称及参数值字典</param>  
        /// <param name="timeout">请求的超时时间</param>  
        /// <param name="userAgent">请求的客户端浏览器信息,可以为空</param>  
        /// <param name="requestEncoding">发送HTTP请求时所用的编码</param>  
        /// <param name="cookies">随同HTTP请求发送的Cookie信息,如果不需要身份验证可以为空</param>  
        /// <returns></returns>  
        public static HttpWebResponse CreatePostHttpResponse(string url,IDictionary<string,string> parameters,int? timeout, string userAgent,Encoding requestEncoding,CookieCollection cookies)  
        {  
            if (string.IsNullOrEmpty(url))  
            {  
                throw new ArgumentNullException("url");  
            }  
            if(requestEncoding==null)  
            {  
                throw new ArgumentNullException("requestEncoding");