在项目开发中遇到了两个团队进行开发,在开发中后台需要调用到另外一个团队写的接口再进行逻辑处理。
当然这些调用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) + "&");
}