当前位置:首页 > C#

HttpWebRequest 发送 post

happyfhb8年前 (2018-10-16)C#2645
摘要:   string strURL = " http://zhaohong.kq07.cn/index.ashx?appid=9AQnOMOs&appsecret=ei3kw9cuGLkZnX8i ";…
   string strURL = "
http://zhaohong.kq07.cn/index.ashx?appid=9AQnOMOs&appsecret=ei3kw9cuGLkZnX8i
";

            System.Net.HttpWebRequest request;

            request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);

            request.Method = "POST";

            request.ContentType = "application/json;charset=utf-8";

            string paraUrlCoded = "{\"shangpin\":[{\"name\":\"手机" + DateTime.Now.ToShortTimeString() + "\",\"price\":\"20\",\"num\":\"5\",\"picurl\":\"
https://img.zcool.cn/community/01b34f58eee017a8012049efcfaf50.jpg\"},{\"name\":\
"手机套" + DateTime.Now.ToShortTimeString() + "\",\"price\":\"20\",\"num\":\"5\",\"picurl\":\"
https://img.zcool.cn/community/01b34f58eee017a8012049efcfaf50.jpg\"},{\"name\":\
"茶杯" + DateTime.Now.ToShortTimeString() + "\",\"price\":\"20\",\"num\":\"5\",\"picurl\":\"
https://img.zcool.cn/community/01b34f58eee017a8012049efcfaf50.jpg\"},{\"name\":\
"笔记本电脑\",\"price\":\"20\",\"num\":\"5\",\"picurl\":\"
https://img.zcool.cn/community/01b34f58eee017a8012049efcfaf50.jpg\
"}]}";

            byte[] payload;

            payload = System.Text.Encoding.GetEncoding("utf-8").GetBytes(paraUrlCoded);

            request.ContentLength = payload.Length;

            Stream writer = request.GetRequestStream();

            writer.Write(payload, 0, payload.Length);

            writer.Close();

            System.Net.HttpWebResponse response;

            response = (System.Net.HttpWebResponse)request.GetResponse();

            System.IO.Stream s;

            s = response.GetResponseStream();

            string StrDate = "";

            string strValue = "";

            StreamReader Reader = new StreamReader(s, Encoding.GetEncoding("utf-8"));

            while ((StrDate = Reader.ReadLine()) != null)

            {

                strValue += StrDate + "\r\n";

            }

            label1.Text = strValue;

 

扫描二维码推送至手机访问。

版权声明:本文由海海日记-冯海滨博客发布,如需转载请注明出处。

本文链接:http://www.fenghaibin.com/?id=1292

“HttpWebRequest 发送 post” 的相关文章

IIS_WPG用户组

IIS_WPG用户组在安装asp.net web应用程序时,发现文件夹的用户权限总设置不对,结果导致读写access数据库文件出错。仔细研究了一下,发现必须要给IIS_WPG用户组足够的权限,程序才能正常运行。IIS_WPG用户组是做什么的?为了管理的方便,在安装 IIS 6 时创建了 IIS_WP…

传智播客.Net精品就业班培训专区目录

[传智播客.Net视频]第1季C#编程基础[传智播客.Net视频]第2季C#面向对象基础    [传智播客.Net视频]第3季WinForm基础  [传智播客.Net视频]第4季SQL从入门到提高    [传智播客.Net视频]第5季ADO.Net&…

c#无返回值函数如何调用

 无返回值函数如何调用 事例 定义一个不需要返回值的函数 none()         static void none()//定义一个不需要返回值的函数        {&nbs…

C#延时方法片段

 label4.Text = "输入非数字字符";                //延时1秒  &…

C# 编写 Windows服务

. 新建一个项目2. 从一个可用的项目模板列表当中选择Windows服务3. 设计器会以设计模式打开4. 从工具箱的组件表当中拖动一个Timer对象到这个设计表面上 (注意: 工具箱中的timer 都是不对的,需要另行添加 详见方法 )&n…

C# windows服务程序中的Timer控件的添加方法

C# windows服务程序中的Timer控件的添加方法

开"工具箱"---右键---"选择项"---找到Timer控件,看好了,这个Timer控件的是system.Timer下的. 可不是System.Windows.Form.然后添加. …

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。