当前位置:网站首页>. Net code to implement get request and post request
. Net code to implement get request and post request
2022-06-13 07:03:00 【AndroidOrCSharp】
GET request :
private JObject doGet(Dictionary<String, String> param)
{
JObject jres = new JObject();
object obj = new { notifyType = 1, taCode = strTANO, tradeDt = DateTime.Now.ToString("yyyyMMdd") };
strData = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
string strURL = "https//192.168.1.1/channel/push";
if (!strURL.EndsWith("?"))
{
strURL = strURL + "?";
}
strURL = strURL + strData;
try
{
// Construct a Web The object of the request
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strURL);
// obtain web Content of the requested response
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
// Construct a StreamReader
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string response = reader.ReadToEnd();
reader.Close();
myResponse.Close();
jres.Add("code", new JValue("0"));
jres.Add("msg", new JValue(response));
}
catch (Exception ex)
{
log.Info(" Message push Get Request exception :" + ex.Message);
jres.Add("code", new JValue("9999"));
jres.Add("msg", new JValue(ex.Message));
}
return jres;
}
POST request :
private JObject doPost(Dictionary<String, String> param)
{
object obj = new { notifyType = 1, taCode = strTANO, tradeDt = DateTime.Now.ToString("yyyyMMdd") };
strData = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
string strURL = "https://192.168.1.1/post";
JObject jres = new JObject();
try
{
byte[] sendData = Encoding.UTF8.GetBytes(strData);
WebClient webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/json");
byte[] retInfo = webClient.UploadData(strURL, "POST", sendData);
string strInfo = System.Text.Encoding.UTF8.GetString(retInfo);
JObject jre = Newtonsoft.Json.JsonConvert.DeserializeObject(strInfo) as Newtonsoft.Json.Linq.JObject;
string requestState = jre["code"] is null ? jre["result"] is null ? "9999" : jre["result"].ToString() : jre["code"].ToString();
if ("000000".Equals(requestState) || "success".Equals(requestState))
{
jres.Add("code", new JValue("0"));
}
else
{
jres.Add("code", new JValue("9999"));
}
}
catch (Exception ex)
{
log.Info(" Message push Post Request exception :" + ex.Message);
jres.Add("code", new JValue("9999"));
jres.Add("msg", new JValue(ex.Message));
}
return jres;
}
边栏推荐
- 牙周炎问题调研(持续进行中)
- June 12, 2022: if there are n*n pieces in an n*n square chessboard, each grid can have exactly one piece. But now some pieces are gathered on a grid, such as 2030100300. The above two-dimensional arra
- 号称下一代监控系统 来看看它有多牛逼
- Tidb data migration (DM) Introduction
- NFV基本概述
- JS case Xiaomi second kill countdown New Year Countdown
- RT thread simulator lvgl control: button button style
- [Tencent Alibaba's most comprehensive collection of test questions] (four sides: three rounds of technology +1 round of HR)
- Evolution in the digital age
- Normalizing y-axis in histograms in R ggplot to proportion
猜你喜欢

RT-Thread 模拟器 simulator LVGL控件:button 按钮事件

怎么写出一份令人惊叹的设计文档?

Nfv basic overview

Ffmpeg compressed video.

Department store center supply chain management system

2022-06-12:在N*N的正方形棋盤中,有N*N個棋子,那麼每個格子正好可以擁有一個棋子。 但是現在有些棋子聚集到一個格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二維數組代錶,一

Tidb statistics

RT thread simulator lvgl control: button button style

基于SSM实现水果商城批发平台
![[cloud native | kubernetes] kubernetes configuration](/img/cb/20595d34a9e203b83dd086cc27037d.png)
[cloud native | kubernetes] kubernetes configuration
随机推荐
Differences between SQL and NoSQL of mongodb series
105. constructing binary trees from preorder and inorder traversal sequences
Why does TCP establish three handshakes and four waves
Department store center supply chain management system
How worker threads in the thread pool are recycled
2022 - 06 - 12: dans un échiquier carré n * N, il y a n * n pièces, donc chaque pièce peut avoir exactement une pièce. Mais maintenant quelques pièces sont rassemblées sur une grille, par exemple: 2 0
json. Stringify() and json The difference between parse () and json Usage of stringify()
105. 从前序与中序遍历序列构造二叉树
【马尔科夫链-蒙特卡罗】马尔科夫链-蒙特卡罗方法对先验分布进行抽样
SDN基本概述
16、 IO stream (II)
IIS batch bind domain name
学习Mysql基础第一天
Periodontitis investigation (ongoing)
Fe of mL: introduction to vintage curve /vintage analysis, calculation logic and detailed introduction to case application
1154. day of the year
检测循环数“142857“
Tidb dashboard modify port
Is it safe for Hangzhou Securities to open an account?
Is it safe to open an account online in Hangzhou?