基于HttpWebRequest,HttpWebResponse发起请求
/// <summary>
/// 获取版本更新信息 GET
/// </summary>
/// <param name="softwareKey">软件的标识</param>
/// <returns></returns>
public static ResponseResult<UpdateInfo> GetUpdateInfo(string softwareKey)
{
ResponseResult<UpdateInfo> updateInfo = new ResponseResult<UpdateInfo>();
if (!IsConnectInternet())
{
updateInfo.statusCode = 404;
return updateInfo;
}
string updateInfoStr = null; #if DEBUG
Uri address = new Uri("http://xxxx/Api/UpdateCenter/GetUpdateInfo?softwareKey=" + softwareKey); #else
Uri address = new Uri("http://xxxx/Api/UpdateCenter/GetUpdateInfo?softwareKey=" + softwareKey);
#endif
try
{ // 使用httpwebrequest调用api接口
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(address);
httpWebRequest.Method = "GET"; HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
updateInfoStr = streamReader.ReadToEnd(); if (!string.IsNullOrWhiteSpace(updateInfoStr))
{
updateInfo = JsonConvert.DeserializeObject<ResponseResult<UpdateInfo>>(updateInfoStr);
return updateInfo;
}
}
catch (Exception ex)
{
}
return null;
}
/// <summary>
/// 报送版本号与序列号 POST
/// </summary>
public static void PostVersionSerial()
{
Thread thread = new Thread(() =>
{
try
{
string result = "";
string JsonStr ="'"+SystemConfigBLL.GetSingle("CompanyInfo").Value+"'";
#if DEBUG
Uri uri = new Uri("http://xxxxx/Api/Customer/Report");
#else
Uri uri = new Uri("http://xxxxx/Api/Customer/Report");
#endif
//向接口发送数据 并得到返回值
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(uri);
objRequest.Method = "POST";
objRequest.ContentType = "application/json";
byte[] byteData = Encoding.UTF8.GetBytes(JsonStr);
objRequest.ContentLength = byteData.Length;
objRequest.GetRequestStream().Write(byteData, 0, byteData.Length); HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
sr.Close();
} ResponseResults<CustomerCode> responseResults = JsonConvert.DeserializeObject<ResponseResults<CustomerCode>>(result); if (!string.IsNullOrEmpty(responseResults.content.code))
{
if (string.IsNullOrEmpty(SystemConfigBLL.GetSingle("CustomerCode").Value))
{
int res = SystemConfigBLL.Update("CustomerCode", responseResults.content.code);
}
}
}
catch
{ } });
thread.IsBackground = true;
thread.Start();
}
基于HttpWebRequest,HttpWebResponse发起请求的更多相关文章
- python 爬虫 基于requests模块发起ajax的post请求
基于requests模块发起ajax的post请求 需求:爬取肯德基餐厅查询http://www.kfc.com.cn/kfccda/index.aspx中指定某个城市地点的餐厅数据 点击肯德基餐厅查 ...
- python 爬虫 基于requests模块发起ajax的get请求
基于requests模块发起ajax的get请求 需求:爬取豆瓣电影分类排行榜 https://movie.douban.com/中的电影详情数据 用抓包工具捉取 使用ajax加载页面的请求 鼠标往下 ...
- 【转】asp.net(c#)使用HttpWebRequest附加携带请求参数以post方式模拟上传大文件(以图片为例)到Web服务器端
原文地址:http://docode.top/Article/Detail/10002 目录: 1.Http协议上传文件(以图片为例)请求报文体内容格式 2.完整版HttpWebRequest模拟上传 ...
- HttpWebRequest,HttpWebResponse的用法和用途
1.用途:HettpWebRequest,HettpWebResponse用途和webServers的作用差不多,都是得到一个页面传过来的值.HttpWebRequest 2.用法:--------- ...
- C#获取网页内容 (WebClient、WebBrowser和HttpWebRequest/HttpWebResponse)
获取网页数据有很多种方式.在这里主要讲述通过WebClient.WebBrowser和HttpWebRequest/HttpWebResponse三种方式获取网页内容. 这里获取的是包括网页的所有信息 ...
- Elasticsearch High Level Rest Client 发起请求的过程分析
本文讨论的是JAVA High Level Rest Client向ElasticSearch6.3.2发送请求(index操作.update.delete--)的一个详细过程的理解,主要涉及到Res ...
- Elasticsearch 基于 URL 的搜索请求
背景 Elasticsearch 不像关系型数据库,没有简易的 SQL 用来查询数据,只能通过调用 RESTful API 实现查询.大体上查询分为两种,基于 URL 的和基于请求主体的.基于 URL ...
- C#网页采集数据的几种方式(WebClient、WebBrowser和HttpWebRequest/HttpWebResponse)
一.通过WebClient获取网页内容 这是一种很简单的获取方式,当然,其它的获取方法也很简单.在这里首先要说明的是,如果为了实际项目的效率考虑,需要考虑在函数中分配一个内存区域.大概写法如下 //M ...
- C#实现通过HttpWebRequest发送POST请求实现网站自动登陆
C#实现通过HttpWebRequest发送POST请求实现网站自动登陆 怎样通过HttpWebRequest 发送 POST 请求到一个网页服务器?例如编写个程序实现自动用户登录,自动提交表单数 ...
- Vue2使用Axios发起请求教程详细
当你看到该文章时希望你已知晓什么是跨域请求以及跨域请求的处理,本文不会赘述 本文后台基于Springboot2.3进行搭建,Controller中不会写任何业务逻辑仅用于配合前端调试 Controll ...
随机推荐
- Zabbix与乐维监控对比分析(八)——其他功能篇
前面我们详细介绍了Zabbix与乐维监控的架构与性能.Agent管理.自动发现.权限管理.对象管理.告警管理.可视化.图形图表及网络功能方面的对比分析,接下来我们将对二者其他功能进行对比分析. 本篇是 ...
- ASP.NET 6.0 Core 迁移 ASP.NET Core 7.0
2022年微软发布了.NET 7, 同时提供了详细的升级迁移方案. Migrate from ASP.NET Core 6.0 to 7.0 今天给大家简单整理.分享一篇文章. 一.首先需要升级Vis ...
- Redefinition of 'y1' as different kind of symbol
Redefinition of 'y1' as different kind of symbol 原因 解释:此次定义的y1变量与函数库中定义的y1重名了,所以编译错误,重定义了y1变量. 解决方法: ...
- 【FAQ】申请运动健康服务验证环节常见问题及解答
华为 HMS Core 运动健康服务(HUAWEI Health Kit)提供原子化数据开放.应用在获取用户数据授权后,可通过接口访问运动健康数据,对用户数据进行读写等操作,为用户提供运动健康类数据服 ...
- Grafana 系列文章(八):Grafana Explore 中的 Inspector
️URL: https://grafana.com/docs/grafana/latest/explore/explore-inspector/ Description: Explore 中的检查器 ...
- Java JDK Proxy和CGLib动态代理示例讲解
简介 代理模式在Java中有很多应用场景,而代理又分静态代码和动态代理.静态代理是编写.编译或加载时织入代码实现,而动态代理则在运行时实现.简单而言,静态代理是在运行前就已经存在,而动态代理则在运行时 ...
- pdf转图片加水印压缩
''' pip install pymupdf pip install pillow ''' import os import uuid import fitz from PIL import Ima ...
- 力扣---1148. 文章浏览 I
Views 表:+---------------+---------+| Column Name | Type |+---------------+---------+| article_i ...
- 00-DLL劫持&C语言远程加载shellcode
0x01 杀软拦截检测规则引导-DLL劫持上线 准备工具 cs vs2019 dll劫持工具:https://bbs.pediy.com/thread-224408.htm 极速PDF:https:/ ...
- P4238 【模板】多项式乘法逆
#include <cstdio> #include <iostream> #define re register using namespace std; typedef l ...