c#--发起一个http请求
来源:互联网 发布:apk软件如何安装 编辑:程序博客网 时间:2024/05/17 19:21
using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.IO;using System; namespace KL.EDMS.Business.Report{ public class FaultCountLogic { //注:本次请求为向androidpnserver发送请求实现后台向客户端的消息推送 public string SentHttpRequest() { //请求路径 string url = "http://localhost:7070/notification.do"; //定义request并设置request的路径 WebRequest request = WebRequest.Create(url); //定义请求的方式 request.Method = "POST"; //初始化request参数 string postData = "action=send&broadcast=Y&uri=112332&username=f8df247d0b2b4277b122f68c94c2caab"; postData +="&title=C#发送后台请求"; postData += "&message=利用C#后台向androidpnserver发送HTTP请求实现客户端的消息推送功能。"; //设置参数的编码格式,解决中文乱码 byte[] byteArray = Encoding.UTF8.GetBytes(postData); //设置request的MIME类型及内容长度 request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; //打开request字符流 Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); //定义response为前面的request响应 WebResponse response = request.GetResponse(); //获取相应的状态代码 Console.WriteLine(((HttpWebResponse)response).StatusDescription); //定义response字符流 dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd();//读取所有 Console.WriteLine(responseFromServer); //关闭资源 reader.Close(); dataStream.Close(); response.Close(); return responseFromServer; } }}
阅读全文
0 0
- c#--发起一个http请求
- python3发起一个http请求
- java 发起HTTP请求
- Java发起Http请求
- 使用http发起请求
- nginx发起http请求
- Java发起http 请求
- 发起Http请求
- java 发起http请求
- C#发起一个请求
- iphone发起http请求代码
- 发起https和http请求
- C# 发起普通http请求
- 他妈的 Python(1):怎么发起一个同步的 HTTP 请求
- 原生JS发起http请求的一个例子,并且接收返回值
- http 使用curl发起https请求
- http 使用curl发起https请求
- http 使用curl发起https请求
- cocos js 在android ios 打开网页
- linux的内存回收和交换
- Android水波纹loading
- Spring 请求参数乱码
- 设计模式概念总结
- c#--发起一个http请求
- Java学习笔记07——Oracle数据库SQL开发基础
- PAT (Advanced Level) Practise 1084 Broken Keyboard (20)
- iOS持久化Core Data之一 CoreDataHelper
- java学习 ----- 类与对象
- 蓝桥杯 ADV-109 算法提高 征税程序
- iOS 调试解决iOS内存泄漏
- 深度学习(六十九)darknet 实现实验 Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffma
- spring @component的作用