在.net中调用别人写的接口获得数据

本文介绍了在.NET项目中如何调用其他团队编写的数据接口,重点在于POST请求的实现,适用于后台逻辑处理中需要跨团队协作的场景。
摘要由CSDN通过智能技术生成

在项目开发中遇到了两个团队进行开发,在开发中后台需要调用到另外一个团队写的接口再进行逻辑处理。

当然这些调用POST、GET跟调用微信和支付宝的接口都是一致的大笑。下面是我整理的调用方法。

话不多说,直接放代码:


SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
sParaTemp.Add("1",参数变量);
sParaTemp.Add("4", 参数变量);
sParaTemp.Add("2", 参数变量);
sParaTemp.Add("3", 参数变量);
//得到序列化的参数值
string data = NetFramework.Helper.wphttppost.datapost(sParaTemp);
//进行post提交
string result = NetFramework.Helper.wphttppost.Post(data, "http://121.22.22.22/接口地址", 6);



-------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.IO;
using System.Text;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;


namespace NetFramework.Helper
{
    public class wphttppost
    {


        public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            //直接确认,否则打不开    
            return true;
        }


        /// <summary>
        /// 得到需要传递的参数格式
        /// </summary>
        /// <param name="sParaTemp">参数键值</param>
        /// <returns></returns>
        public static string datapost(SortedDictionary<string, string> sParaTemp)
        {
            Encoding myEncoding = Encoding.GetEncoding("gb2312");  
            StringBuilder prestr = new StringBuilder();
            foreach (KeyValuePair<string, string> temp in sParaTemp)
            {
                prestr.Append(temp.Key + "=" + HttpUtility.UrlEncode(temp.Value, myEncoding) + "&");
            }
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值