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. vue.js组件之j间的通讯三,通过单一事件来管理组件通讯

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  2. react 中文文档案例一 (倒计时)

    1.函数试组件 import React from 'react'; import ReactDOM from 'react-dom'; function Clock(props){ return( ...

  3. ubuntu下中文乱码解决

    这个方法只对该用户有效. 方法二:修改/etc/environment,增加以下内容: LANGUAGE=”zh_CN:zh:en_US:en” LANG=zh_CN.GBK

  4. 计算机学院大学生程序设计竞赛(2015’12)The collector’s puzzle

    Problem Description There is a collector who own many valuable jewels. He has a problem about how to ...

  5. day25 网络编程之socket sc架构

    1.  为什么要学习socket? socket就是网络通信的工具,任何一门语言都有socket,他不是任何一个语言的专有名词,而是大家通过自己的程序与其他电脑进行网络通信的时候都用它. 2.  客户 ...

  6. c#操作windows本地账户

    using System;using System.Collections.Generic;using System.Text;using System.Runtime.InteropServices ...

  7. 阿里云ECS服务器FileZilla'被动模式失败'的处理办法

    现象:FileZilla客户端连接服务器报错:“状态:    服务器发回了不可路由的地址.被动模式失败.” 解决办法:1.在[FileZilla Server]-Edit-Settings-Passi ...

  8. centos7安装与卸载软件

    安装 yum install 服务名 查看服务名 rpm -qa |grep -i aerospike 或者 yum list installed | grep aerospike 卸载 yum re ...

  9. esper(1)-窗口概述

    Time Window: Length Window: Time Batch Window: 带batch的是所有的都执行完后,在触发UpdateListener,如下边例子: public clas ...

  10. java——链表映射 LinkedListMap

    好像也不是基于链表来实现的,而是采用与链表类似的节点形式重新定义了一个节点内部类,以此来实现映射 public class LinkedListMap<K, V> implements M ...