POST方法的参数怎么写?

z62333302y 2013-07-24 06:44:36
public static string PostModel(string strUrl, string strParm)
{
Encoding encode = System.Text.Encoding.Default;

byte[] arrB = encode.GetBytes(strParm);
string strBaseUrl = null;

HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(strUrl);
myReq.Method = "POST" ;
myReq.ContentType = "application/x-www-form-urlencoded";
myReq.ContentLength = arrB.Length;
Stream outStream = myReq.GetRequestStream();
outStream.Write(arrB,0,arrB.Length);

.... 后续代码不贴了,贴了也没用

我想问一下,这个strParm的参数应该怎么写呢?
POST方法不是成对出现的吗?

谁能给我写个调用该方法的例子?
指教了~~
...全文
209 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
guwei4037 2013-07-24
refer:
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://fanyi.baidu.com/transcontent");
            Encoding encoding = Encoding.UTF8;
            string param = "ie=utf-8&source=txt&query=hello&t=1327829764203&token=8a7dcbacb3ed72cad9f3fb079809a127&from=auto&to=auto";
            //encoding.GetBytes(postData);
            byte[] bs = Encoding.ASCII.GetBytes(param);
            string responseData = String.Empty;
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = bs.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(bs, 0, bs.Length);
                reqStream.Close();
            }
            using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
                {
                    responseData = reader.ReadToEnd().ToString();
                }
                Response.Write(responseData);
            }
回复
相关推荐
发帖
C#
创建于2007-09-28

10.6w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2013-07-24 06:44
社区公告

让您成为最强悍的C#开发者