注意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. Android UI 之实现多级列表TreeView

    所谓TreeView就是在Windows中常见的多级列表树,在Android中系统只默认提供了ListView和ExpandableListView两种列表,最多只支持到二级列表的实现,所以如果想要实 ...

  2. hdfs中block的使用情况,副本所在情况等等

    hadoop fsck /user/hive/warehouse/dataplat.db/hive_datacppa2xsourcendchinaraw/partitiondate=2016-11-2 ...

  3. .NET 农码一生

    农码一生博文索引 http://www.cnblogs.com/zhaopei/p/Indexes.html 那些年搞不懂的术语.概念:协变.逆变.不变体 http://www.cnblogs.com ...

  4. 11 JSP/EL表达式/EL函数

    JSP      * 概述: JSP(Java Server Pages)与Java Servlet一样,是在服务器端执行的不同的是先由服务器编译部署成Servlet执行      * JSP的运行原 ...

  5. TComboBox; 指定某一行,不给下拉,只读ReadOnly 伪装 实现

    //cbb1: TComboBox; 指定某一行,不给下拉,自读伪装 实现: cbb1.Style :=csSimple; //设定style 不可以下拉 cbb1.ItemIndex := ; // ...

  6. dos2unix对shell脚本程序的解救

    删除多个文件,不询问是否删除:rm -rf *.log (利用通配符) dos2unix 文件名:由于windows系统中文件的结束符和linux下文件的结束符不同,一些对语法要求较严格的脚本语言就会 ...

  7. RecyclerView item 状态错乱

    adapter中: private List<Integer> checkboxUserIdList = new ArrayList<>(); 在如下这个方法中: public ...

  8. CSS笔记2

    1.     CSS基础选择器 html负责结构 ,css负责样式,js负责行为 css写在head标签里面,容器style标签 <style type="text/css" ...

  9. *HDU1151 二分图

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  10. 如何解决google ping不通的问题。

    1. 用http://ping.chinaz.com/ ping google的域名. 2. 会ping出很多ip,但是chinaz用的是测试网点去ping的,不是你本地宽带, 所以把ping出ip拷 ...