content-type:  application/~~~~~

  /// <summary>
/// Post数据到网站
/// </summary>
/// <param name="posturl">网址</param>
/// <param name="postData">参数</param>
/// <returns></returns>
public static string postHTTP(string posturl, string postData)
{
Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding encoding = System.Text.Encoding.GetEncoding("UTF-8");
byte[] data = encoding.GetBytes(postData);
// 准备请求...
try
{
// 设置参数
request = WebRequest.Create(posturl) as HttpWebRequest;
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
outstream = request.GetRequestStream();
outstream.Write(data, , data.Length);
outstream.Close();
//发送请求并获取相应回应数据
response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
//返回结果网页(html)代码
string content = sr.ReadToEnd();
string err = string.Empty;
return content;
}
catch (Exception ex)
{
string err = ex.Message;
return string.Empty;
}
}

IT用语:通常这种同操作系统或其他应用程序进行交互的应用程序请求称为应用程序接口,也就是常常提起的API

当content-type:  application/json时

   string tokenJson = "";
Dictionary<string, string> par = new Dictionary<string, string>();
par.Add("account", name);
par.Add("secret", pwd);
tokenJson = Tool.Json(par);
tokenJson = Tool.Remove(tokenJson); string tokenResult = Tool.postHTTP("http://61.128.195.29:8180/bskyAPI/api/GP/GetToken", tokenJson);
JObject tokenData = JObject.Parse(tokenResult);
string token = tokenData["data"]["token"].ToString();
return token;

当content-type:  application/x-www-from-urlencode时

参数格式为:name="zzzz"&id="aaaaa"

get/post 接口调用的更多相关文章

  1. 《C#微信开发系列(3)-获取接口调用凭据》

    3.0获取接口调用凭据 ①接口说明 access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token.开发者需要进行妥善保存.access_token的存储至少要保留 ...

  2. asp.net mvc短信接口调用——阿里大于API开发心得

    互联网上有许多公司提供短信接口服务,诸如网易云信.阿里大于等等.我在自己项目里需要使用到短信服务起到通知作用,实际开发周期三天,完成配置.开发和使用,总的说,阿里大于提供的接口易于开发,非常的方便,短 ...

  3. PHP 使用 curl_* 系列函数和 curl_multi_* 系列函数进行多接口调用时的性能对比

    在页面中调用的服务较多时,使用并行方式,即使用 curl_multi_* 系列函数耗时要小于 curl_* 系列函数. 测试环境 操作系统:Windows x64 Server:Apache PHP: ...

  4. Spring AOP在函数接口调用性能分析及其日志处理方面的应用

    面向切面编程可以实现在不修改原来代码的情况下,增加我们所需的业务处理逻辑,比如:添加日志.本文AOP实例是基于Aspect Around注解实现的,我们需要在调用API函数的时候,统计函数调用的具体信 ...

  5. 基于JAVA的全国天气预报接口调用示例

    step1:选择本文所示例的接口"全国天气预报接口" url:https://www.juhe.cn/docs/api/id/39/aid/87step2:每个接口都需要传入一个参 ...

  6. bugzilla4的xmlrpc接口api调用实现分享: xmlrpc + https + cookies + httpclient +bugzilla + java实现加密通信下的xmlrpc接口调用并解决登陆保持会话功能

    xmlrpc .  https . cookies . httpclient.bugzilla . java实现加密通信下的xmlrpc接口调用并解决登陆保持会话功能,网上针对bugzilla的实现很 ...

  7. Spring框架下的 “接口调用、MVC请求” 调用参数、返回值、耗时信息输出

    主要拦截前端或后天的请求,打印请求方法参数.返回值.耗时.异常的日志.方便开发调试,能很快定位到问题出现在哪个方法中. 前端请求拦截,mvc的拦截器 import java.util.Date; im ...

  8. 云极知客开放平台接口调用方法(C#)

    云极知客为企业提供基于SAAS的智能问答服务.支持企业个性化知识库的快速导入,借助语义模型的理解和分析,使企业客户立即就拥有本行业的24小时客服小专家.其SAAS模式实现零成本投入下的实时客服数据的可 ...

  9. ThinkPHP整合支付宝即时到账接口调用

    首先是在支付宝的蚂蚁金服开放平台下载PHP的demo: https://doc.open.alipay.com/doc2/detail?treeId=62&articleId=103566&a ...

  10. OpenCV4Android开发之旅(一)----OpenCV2.4简介及 app通过Java接口调用OpenCV的示例

    转自:  http://blog.csdn.net/yanzi1225627/article/details/16917961 开发环境:windows+ADT Bundle+CDT+OpenCV-2 ...

随机推荐

  1. Pi 在Windows下面使用远程桌面登录

    1.删除系统自带的xrdp 输入命令sudo apt-get purge xrdp pi@raspberrypi:~ $ sudo apt-get purge xrdp 正在读取软件包列表... 完成 ...

  2. QT的配置及目录结构

    作者:一去丶二三里 来源:CSDN 原文:https://blog.csdn.net/liang19890820/article/details/51774724 注意:所有的配置中,/user中的/ ...

  3. Polynomial ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    1 Fundamentals A polynomial is either zero, or can be written as the sum of one or more non-zero ter ...

  4. UWP开发入门(八)——聊天窗口和ItemTemplateSelector

    我们平常用的最多的APP可能就是企鹅和微信了.有没有想过聊天窗口如何实现的?本篇我们将简单模拟一个聊天窗口. 聊天窗口大致上就是消息的一个集合列表.集合列表最常见的展现形式无非就是ListView.可 ...

  5. RabbitMq初探——用队列实现RPC

    rabbitmq构造rpc 前言 rpc——remote procedure call 远程调用.在我接触的使用过http协议.thrift框架来实现远程调用.其实消息队列rabbitmq也可以实现. ...

  6. Exp5 MSF基础应用 20164323段钊阳

    网络对抗技术 20164323 Exp5 MSF基础应用 靶机 ip:192.168.1.229 kali ip:192.168.1.216 exploit选取 主动攻击:ms17_010_psexe ...

  7. npm 查看express版本

    npm list 名称    eg: npm list express

  8. Redis Sentinel初体验

        自Redis增加Sentinel集群工具以来,本博主就从未尝试过使用该工具.最近在调研目前主流的Redis集群部署方案,所以详细地看了一遍官方对于Sentinel的介绍并在自己的台式机上完成了 ...

  9. PHP消息队列实现

    一个经典的消息队列就是这样的,主要是入队出队操作. shell脚本日志输出 学习地址:http://www.imooc.com/article/19111

  10. 递归实现进制转换(C++版)

    上次呢,我们留下了一道题,今天我们来一起看一看: 题目链接:https://www.cnblogs.com/gaozirong/p/10547434.html 这是我写的程序,大家可以对照参考一下(C ...