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方法不是成对出现的吗?

谁能给我写个调用该方法的例子?
指教了~~
...全文
429 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
全栈极简 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);
            }

110,975

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧