.net 控制器调用外部链接传参方法
public class RequestHelper
{
/// <summary>
/// 发起post请求
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">url</param>
/// <param name="postData">post数据</param>
/// <returns></returns>
public static T PostResponse<T>(string url, object postData)
{
string json = JsonHelper.ToJson(postData);
if (url.StartsWith("https"))
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
HttpContent httpContent = new StringContent(json);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpClient httpClient = new HttpClient();
T result = default(T);
HttpResponseMessage response = httpClient.PostAsync(url, httpContent).Result;
if (response.IsSuccessStatusCode)
{
Task<string> t = response.Content.ReadAsStringAsync();
string s = t.Result;
result = JsonHelper.DeSerializeObject<T>(s);
}
return result;
}
/// <summary>
/// 发起get请求
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">url</param>
/// <returns></returns>
public static T GetResponse<T>(string url)
{
if (url.StartsWith("https"))
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
HttpClient httpClient = new HttpClient();
T result = default(T);
HttpResponseMessage response = httpClient.GetAsync(url).Result;
if (response.IsSuccessStatusCode)
{
Task<string> t = response.Content.ReadAsStringAsync();
string s = t.Result;
result = JsonHelper.DeSerializeObject<T>(s);
}
return result;
}
}
调用:
List<double[]> logAndLat = new List<double[]>();
logAndLat.Add(new double[] {113.326196, 34.715269 });
logAndLat.Add(new double[] {113.321561, 34.722183});
public static double GetArea(List<double[]> points)
{
string result = RequestHelper.PostResponse<string>("url", points);
double.TryParse(result, out double r);
return r;
}
.net 控制器调用外部链接传参方法的更多相关文章
- 9-11.Yii2.0框架控制器分配视图并传参xss攻击脚本视图的过滤
目录 一维数组传参 新建控制器: 新建view模板 二维数组传参 新建控制器: 新建view模板 视图非法字符的过滤 新建控制器: 新建view模板 一维数组传参 新建控制器: D:\xampp\ht ...
- 学习chrome 插件 DHC ,http请求传参方法
DHC的简介 DHC是一款可以帮助用户使用chrome插件模拟HTTP客户端发送测试数据到服务器的谷歌浏览器插件,在chrome中安装了DHC插件以后,就可在服务器端代码初步完成的时候,使用DHC进行 ...
- PHP实现对站点内容外部链接的过滤方法
熟悉SEO的朋友都知道,对于网站外部链接失效的情况如果链接带有rel="nofollow"属性可以避免不必要的损失.本文就以实例形式演示了PHP实现对站点内容外部链接的过滤方法.具 ...
- jquery-uploadify传参方法
jquery-uploadify传参方法$(document).ready(function () { $("#uploadify").uploadify({ 'uploader' ...
- js方法之间的调用之——传参方法
在最近项目需求中发现,完成一些功能的时候总是要调很多结构类似的方法,写起来很繁琐,所以就想写一个“万能”方法,是的代码更简洁.即:把一个方法作为参数传给这个“万能”方法,让它去执行你给定的方法,就类似 ...
- 定时器setTimeout()的传参方法
更具体的代码:http://www.cnblogs.com/3body/p/5416830.html // 由于setTimeout()的延迟执行特性,所以在执行的函数中直接使用外部函数的变量是无法获 ...
- winform下调用webservice,传参List<string>
用c#做了一个webservice,其中一个接口是public bool AddReturns(List<string> SQLStringList). 然后在另一个c#做的winform ...
- AngularJS中页面传参方法
1.基于ui-router的页面跳转传参 (1) 用ui-router定义路由,比如有两个页面,一个页面(producers.html)放置了多个producers,点击其中一个目标,页面跳转到对应的 ...
- TKinter当Label绑定bind事件时传参方法
记录下tkinter的 当在label绑定bind事件时,遇到需要传参时的解决方法(因为有event存在 所以不能直接传参) https://www.cnblogs.com/liyuanhong/ar ...
随机推荐
- [PowerShell] check PowerShell Version
如果你已经开始在日常的工作中大量使用PowerShell自动化重复工作.建议你使用3.0以上的版本. 可以使用如下命令检测你的PS版本 如需要安装PowerShell,可以参看https://tech ...
- vue js 实现 树形菜单
添加一个模板.<template id="menu-template"> <li v-if="model.nodes!=undefined"& ...
- 奇妙的 clip-path 几何图形
CSS 新属性 clip-path,意味裁剪路径的意思,让我们可以很便捷的生成各种几何图形. clip-path 通过定义特殊的路径,实现我们想要的图形.而这个路径,正是 SVG 中的 path . ...
- C#后端调用WebApi地址
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using Syst ...
- Codeforces Beta Round #87 (Div. 2 Only)-Party(DFS找树的深度)
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exa ...
- jvm问题定位:cpu持续25%
某次代码提交后审核,观察应用CPU占用持续25%, 感觉应该是某个线程写的有问题, 在linux服务器上查看cpu却是正常 windows平台线程查看工具: Process Explorer, ...
- 信息领域热词分析系统--python统计
统计词语出现的频率,并且按从高到低的顺序报错在文件中 def main(): file=open("F:\大数据\大作业\分词后的文件\data4_xinxi.txt",'r') ...
- java——链表映射 LinkedListMap
好像也不是基于链表来实现的,而是采用与链表类似的节点形式重新定义了一个节点内部类,以此来实现映射 public class LinkedListMap<K, V> implements M ...
- vue中组件传值方式汇总
在应用复杂时,推荐使用vue官网推荐的vuex,以下讨论简单SPA中的组件间传值. 一.路由传值 路由对象如下图所示: 在跳转页面的时候,在js代码中的操作如下,在标签中使用<router-li ...
- 2018.6.1学习CSS5里顺丰盒子小问题
在制作下面这样的小盒子时 编写的代码 首先要对li元素设置浮动. 在设置这个li元素下面的a元素时, 因为没有转行内块,inline-block,结果显示出来的页面,鼠标在经过这个选择时(:hover ...