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 控制器调用外部链接传参方法的更多相关文章

  1. 9-11.Yii2.0框架控制器分配视图并传参xss攻击脚本视图的过滤

    目录 一维数组传参 新建控制器: 新建view模板 二维数组传参 新建控制器: 新建view模板 视图非法字符的过滤 新建控制器: 新建view模板 一维数组传参 新建控制器: D:\xampp\ht ...

  2. 学习chrome 插件 DHC ,http请求传参方法

    DHC的简介 DHC是一款可以帮助用户使用chrome插件模拟HTTP客户端发送测试数据到服务器的谷歌浏览器插件,在chrome中安装了DHC插件以后,就可在服务器端代码初步完成的时候,使用DHC进行 ...

  3. PHP实现对站点内容外部链接的过滤方法

    熟悉SEO的朋友都知道,对于网站外部链接失效的情况如果链接带有rel="nofollow"属性可以避免不必要的损失.本文就以实例形式演示了PHP实现对站点内容外部链接的过滤方法.具 ...

  4. jquery-uploadify传参方法

    jquery-uploadify传参方法$(document).ready(function () { $("#uploadify").uploadify({ 'uploader' ...

  5. js方法之间的调用之——传参方法

    在最近项目需求中发现,完成一些功能的时候总是要调很多结构类似的方法,写起来很繁琐,所以就想写一个“万能”方法,是的代码更简洁.即:把一个方法作为参数传给这个“万能”方法,让它去执行你给定的方法,就类似 ...

  6. 定时器setTimeout()的传参方法

    更具体的代码:http://www.cnblogs.com/3body/p/5416830.html // 由于setTimeout()的延迟执行特性,所以在执行的函数中直接使用外部函数的变量是无法获 ...

  7. winform下调用webservice,传参List<string>

    用c#做了一个webservice,其中一个接口是public bool AddReturns(List<string> SQLStringList). 然后在另一个c#做的winform ...

  8. AngularJS中页面传参方法

    1.基于ui-router的页面跳转传参 (1) 用ui-router定义路由,比如有两个页面,一个页面(producers.html)放置了多个producers,点击其中一个目标,页面跳转到对应的 ...

  9. TKinter当Label绑定bind事件时传参方法

    记录下tkinter的 当在label绑定bind事件时,遇到需要传参时的解决方法(因为有event存在 所以不能直接传参) https://www.cnblogs.com/liyuanhong/ar ...

随机推荐

  1. redis数据库介绍(NoSql数据库)

  2. HDU1085 Holding Bin-Laden Captive!

    Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long t ...

  3. java重载equals和hashCode

    class Employee { private int salary; private java.util.Date hireDay; private String name; public int ...

  4. hdu1698 线段树(区间更新~将区间[x,y]的值替换为z)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. msyql操作100题

    1.1.1 开启MySQL服务 /etc/init.d/mysqld start 使用/etc/init.d/mysqld start命令启动数据库的本质就相当于执行mysqld_safe --use ...

  6. Tomcat-猫

    第1章 Tomcat简介 Tomcat  是一个web服务器 ,类似nginx,apache的http Nginx  http 只能处理html等静态文件jpg() 网页分为静态网页(以.html 或 ...

  7. 浅谈ORM操作

    2. ORM(对象关系映射) 1. 映射的关系 DB ORM 数据表 <--> 类 数据行 <--> 对象 字段 <--> 属性 2. Django项目使用MySQ ...

  8. NETSpider 网络蜘蛛采集工具

    NETSpider网站数据采集软件是一款基于.Net平台的开源软件.软件部分功能是基本Soukey软件进行开发的.这个版本采用VS2010+.NET3.5进行开发的.NETSpider采摘当前提供的主 ...

  9. zabbix 告警 JXM

    告警 虚拟机上网 [root@test1 alertscripts]# route -n [root@test1 alertscripts]# route add default gw 172.25. ...

  10. nginx安装及高可用

    nginx的安装: server1: tar zxf nginx-1.14.0.tar.gz cd nginx-1.14.0/src/core/ vim nginx.h cd /root/nginx- ...