注意post的参数组合

HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.KeepAlive = true;
request.AllowAutoRedirect = false;
request.ContentType = "application/x-www-form-urlencoded";
byte[] postdatabtyes = Encoding.UTF8.GetBytes("param={"imsi":"","session":"hwJPCFmgNRtyOED91iTwpteCY"}");
request.ContentLength = postdatabtyes.Length;
Stream requeststream = request.GetRequestStream();
requeststream.Write(postdatabtyes, , postdatabtyes.Length);
requeststream.Close();
string resp;
try{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
resp = sr.ReadToEnd();
}
}

另外一种:

、以Post方式获取

  using System.Web;

  Uri address = new Uri("http://api.search.yahoo.com/ContentAnalysisService/V1/termExtraction");

  // Create the web request
  HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;   // Set type to POST
  request.Method = "POST";
  request.ContentType = "application/x-www-form-urlencoded";   // Create the data we want to send
  string appId = "YahooDemo";
  string context = "Italian sculptors and painters of the renaissance"
  + "favored the Virgin Mary for inspiration";
  string query = "madonna";   StringBuilder data = new StringBuilder();
  data.Append("appid=" + HttpUtility.UrlEncode(appId));
  data.Append("&context=" + HttpUtility.UrlEncode(context));
  data.Append("&query=" + HttpUtility.UrlEncode(query));   // Create a byte array of the data we want to send
  byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());   // Set the content length in the request headers
  request.ContentLength = byteData.Length;   // Write data
  using (Stream postStream = request.GetRequestStream())
  {
  postStream.Write(byteData, , byteData.Length);
  }   // Get response
  using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
  {
  // Get the response stream
  StreamReader reader = new StreamReader(response.GetResponseStream());   // Console application output
  Console.WriteLine(reader.ReadToEnd());
  }
  三、HTTP 验证请求   有些朋友在调用Restful Api时,可能要提供用户名和密码进行Http身份验证,这里我们可以通过为请求增加一个 NetworkCredentials 实例来完成.   // Create the web request
  HttpWebRequest request
  = WebRequest.Create("https://api.del.icio.us/v1/posts/recent") as HttpWebRequest;   // Add authentication to request
  request.Credentials = new NetworkCredential("username", "password");   // Get response
  using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
  {
  // Get the response stream
  StreamReader reader = new StreamReader(response.GetResponseStream());   // Console application output
  Console.WriteLine(reader.ReadToEnd());
  }

.net 调用java rest ful api 实例的更多相关文章

  1. 调用java rest ful 接口实例

    HttpWebRequest request = WebRequest.Create("http://192.168.0.99:8080/wzh-webservice/rest/login? ...

  2. C#调用Java方法(详细实例)

    C#可以直接引用C++的DLL和转换JAVA写好的程序.最近由于工作原因接触这方面比较多,根据实际需求,我们通过一个具体例子把一个JAVA方法转换成可以由C#直接调用的DLL C#调用c++ C#调用 ...

  3. PHP调用JAVA的WebService简单实例

    使用PHP调用JAVA语言开发的WebService.客户端提交两个String类型的参数,服务端返回一个对象类型.服务端使用AXIS-1.4作为SOAP引擎.客户端为PHP5.2.9,使用NuSOA ...

  4. Java 8 Stream API实例

    一.开篇 Stream?其实就是处理集合的一种形式,称之为流,在Java8中被引入,可被Collection中的子类调用. 作用?简化代码,提升你的开发效率. 不会?看完这篇你就能自己上手了! 二.实 ...

  5. .NET调用腾讯云API实例

    最近项目有用到腾讯云的身份识别接口,话不多说,直接上代码: private void IDCardVerification(HttpContext context) { string imgStr = ...

  6. java使用在线api实例

    字符串 strUrl为访问地址和参数 public String loadAddrsApi() { StringBuffer sb; String strUrl = "https://api ...

  7. NET调用Java之100-Continue的坑

    场景:这段时间开发的时候遇到了需要NET调用java的restful api的情况,java端用的服务器是tomcat,框架是spring boot,net调用java端的接口之后只要java端的接口 ...

  8. C#调用Java方法

    C#调用Java方法(详细实例) 阅读目录 C#调用c++ C#调用JAVA方法 C#可以直接引用C++的DLL和转换JAVA写好的程序.最近由于工作原因接触这方面比较多,根据实际需求,我们通过一个具 ...

  9. Java | Spring Boot Swagger2 集成REST ful API 生成接口文档

      Spring Boot Swagger2 集成REST ful API 生成接口文档 原文 简介 由于Spring Boot 的特性,用来开发 REST ful 变得非常容易,并且结合 Swagg ...

随机推荐

  1. 如何查看OpenCv的源代码

    需要移植部分opencv的算法,不得不查看opencv的原始代码. 在一般的代码调试中一般只能看到一些opencv的函数声明和定义,看不到内部执行过程,需要利用 CMake导出opencv 源码,生成 ...

  2. Linux 下MySql 重置密码

    1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...

  3. CocoaPods安装和使用

    CocoaPods是iOS最常用的第三方类库管理工具,绝大部分有名的开源类库都支持CocoaPods. CocoaPods是用Ruby实现的,要想使用它首先需要有Ruby的环境.幸运的是OS X系统默 ...

  4. ZeroMQ接口函数之 :zmq_unbind - 停止连接外来的请求

    ZeroMQ 官方地址 :http://api.zeromq.org/4-2:zmq_unbind zmq_unbind(3) ØMQ Manual - ØMQ/4.1.0 Name zmq_unbi ...

  5. tomcat配置https

    1.开启使用https协议 编辑tomcat目录下的conf/server.xml文件 <Connector port="443" protocol="HTTP/1 ...

  6. chrome浏览器 模拟访问移动端

    谷歌Chrome浏览器,可以很方便地用来当3G手机模拟器.在Windows的[开始]-->[运行]中输入以下命令,启动谷歌浏览器,即可模拟相应手机的浏览器去访问3G手机网页: 谷歌Android ...

  7. WPF整理-自定义一个扩展标记(custom markup extension)

    "Markup extensions are used to extend the capabilities of XAML, by providing declarativeoperati ...

  8. 最难面试的IT公司之ThoughtWorks代码挑战——FizzBuzzWhizz游戏(C#解法)

    原题 看到那么多人看到前面这么糟粕的代码各种不忍直视后,楼主还是把最终实现放在页首吧.             Console.WriteLine("说出三个不同的特殊数,用','隔开 &q ...

  9. poj1664-放苹果(递归)

    一,题意: M个苹果放在N个盘子里,允许有盘子空着,问共有多少种不同的分法. 二,思路: 递归的思想求解: 1,有反复执行的过程(调用本身) 第一种情况n>m : 必定有 n-m 个盘子空着,去 ...

  10. Python环境安装

    Windows: 1.Python安装包下载 可以去官网下载安装包:https://www.python.org/downloads/ 2.Python安装 默认安装路径:C:\python27:也可 ...