当前位置:首页 > C#

HttpWebRequest 发送 post

happyfhb8年前 (2018-10-16)C#2565
摘要:   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” 的相关文章

vb.net 多线程写法

注意 只能调用 不带参数的 sub 如果调用不同类的sub需要定义调用的sub是shared 是共享的 才可以的。相关语法Imports SystemImports System.Threading  '导入系统进程 Public Class Form1 &n…

IIS_WPG用户组

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

asp.net substring截取函数详细用法

asp.net  substring截取函数详细用法字符串截取,substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串。substring(int beginIndex, int endIndex)  返回一个新字符串,它是此字符串的一…

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

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

学习心得 数据库连接类的书写规范

一般的规范都是建立3个类文件类1:字段(属性)model类2:方法(函数) dal类3:辅助或者就是 本来可以直接通过dal调用的方法 我在重写一遍 起中转作用 可以使程序更加清晰  bll…

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

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

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

发表评论

访客

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