当前位置:首页 > C#

HttpWebRequest 发送 post

happyfhb8年前 (2018-10-16)C#2659
摘要:   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…

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

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

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

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

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

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

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

C#  Windows服务 调试方法

C# Windows服务 调试方法

1. 首先在你的服务源代码中添加一个定时器。2. 将定时器设置为可用状态 并且在定时器中加代码 并设置定时器的定时时间 。3. 编译和安装好服务。4. 在定时器代码里面下断点。 5. 在服务控制台管理器中启动服务。以下操作必须在定时器设置的秒内 秒内完成,否则无法进入调试状态。6. VS2…

C#如何检测指定的Windows服务是否启动

C#如何检测指定的Windows服务是否启动

 在项目中,特别是安装项目中我们经常要判断一些服务是否启动(判断SQL Server是否启动最常见),在.net中我们如何判断指定的Windows服务是否启动呢?首先要知道Windows服务的显示名称,这里以IIS检测为例,我们知道IIS的显示名称是"IIS Admin"…

发表评论

访客

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