c# restsharp官网_hbase shell put

c# restsharp官网_hbase shell putusingSystem;usingSystem.Net.Http;usingSystem.Threading.Tasks;usingSystem.Collections.Generic;usingNewtonsoft.Json;usingSystem.Net;usingSystem.IO;usingSystem.Text;usingRestSharp;namespaceHttpClientQuery{classPageInfo{publicintstar

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Net;
using System.IO;
using System.Text;
using RestSharp;

namespace HttpClientQuery
{

class PageInfo
{

public int start { get; set; } //得是public类型

public string table { get; set; }

}

class FilterData
{

public string name { get; set; }

public string value { get; set; }

}

class DocQueryParam
{

public string id { get; set; }

public List<FilterData> filterData { get; set; }

public List<PageInfo> paginationInfo { get; set; }

public int searchType { get; set; }

public string tablename { get; set; }

}

class FileInfo
{

public string fileId { get; set; }
public string name { get; set; }
public int fileSize { get; set; }
public string fileType { get; set; }
public int level { get; set; }
public DateTime recordTime { get; set; }

}

class DocQueryResult
{

public Boolean result { get; set; }
public string errMessage { get; set; }
public string queryId { get; set; }
public List<FileInfo> queryFileList { get; set; }
public List<PageInfo> paginationHistoryInfo { get; set; }
public string IsEnd { get; set; }

}

class DocQuery
{

public DocQuery()
{

}
/// <summary>
/// 使用get方法异步请求
/// </summary>
/// <param name=”url”>目标链接</param>
/// <returns>返回的字符串</returns>
public static async Task<string> postAsync(string url, String jsonStr)
{

HttpClient client = new HttpClient(new HttpClientHandler() { UseCookies = false });

HttpContent content = new StringContent(jsonStr);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(“application/json”);

HttpResponseMessage response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();//用来抛异常的
string responseBody = await response.Content.ReadAsStringAsync();

Console.WriteLine(responseBody);

return responseBody;

}

public static string post(string url, string postdata)
{

HttpWebResponse hw;
string result = string.Empty;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = “POST”;
req.ContentType = “application/json”;
#region 添加Post 参数
byte[] data = Encoding.UTF8.GetBytes(postdata);
req.ContentLength = data.Length;
using (Stream reqStream = req.GetRequestStream())
{

reqStream.Write(data, 0, data.Length);//将post对象放入请求流中
reqStream.Close();
}
#endregion
try
{

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{

result = reader.ReadToEnd();
}
}
catch (WebException w)
{

hw = (HttpWebResponse)w.Response;
StreamReader sr = new StreamReader(hw.GetResponseStream(), Encoding.UTF8, false);
result = sr.ReadToEnd();
}
return result;
}

public static DocQueryResult restPost(string postdata, string url, string query)
{

RestSharp.RestClient client = new RestSharp.RestClient(url);
RestRequest req = new RestRequest(query, Method.POST);
req.RequestFormat = RestSharp.DataFormat.Json;
//req.AddHeader(“cache-control”, “no-cache”);

req.AddJsonBody(postdata);
//IRestResponse rsp = client.Execute(req);
//return rsp.Content;
IRestResponse<DocQueryResult> rsp = client.Execute<DocQueryResult>(req);
DocQueryResult result = rsp.Data;
return result;
}

public void test()
{

DocQueryParam docQueryParam = new DocQueryParam();
docQueryParam.id = “2311”;
docQueryParam.searchType = 2;
docQueryParam.tablename = “c_data”;

List<FilterData> filterDataList = new List<FilterData>();

FilterData filterData = new FilterData();
filterData.name = “model”;
filterData.value = “L”;
filterDataList.Add(filterData);

filterData = new FilterData();
filterData.name = “batch”;
filterData.value = “02”;
filterDataList.Add(filterData);

docQueryParam.filterData = filterDataList;

List<PageInfo> pageInfoList = new List<PageInfo>();

PageInfo pageInfo = new PageInfo();
pageInfo.start = 20;
pageInfo.table = “c_data”;
pageInfoList.Add(pageInfo);

docQueryParam.paginationInfo = pageInfoList;

//序列化
//var jsonStr = JsonConvert.SerializeObject(docQueryParam);
//Console.WriteLine(“docQuery json str: ” + jsonStr);

string url = “http://192.168.1.100:8080/archive/archiveQuery”;

var ret = DocQuery.postAsync(url, jsonStr); //给调用该方法的方法加上async
//DocQueryResult docQueryResult = JsonConvert.DeserializeObject<DocQueryResult>(ret);
//var docQueryResult = JsonConvert.DeserializeObject<DocQueryResult>(ret.Result);
//string isend = docQueryResult.getIsEnd();

Console.ReadKey();

}

}
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/195854.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • (干货)结合Scikit-learn介绍几种常用的特征选择方法

    系统版本:window7(64bit)python版本:python3.5我的GitHub:https://github.com/weepon写在前面:前段时间正好用到特征选择的知识,有幸读到这篇文章,本文也主要参考这篇文章写成,但与原文章有不同之处:第一、纠正了原始文章中的代码错误,使其能用python3.5正常运行;第二、增加了一些新的特征选择内容,使其更加完善。本文中

    2022年4月8日
    41
  • 力争群雄:2012年度IT博客大赛100强脱颖而出[通俗易懂]

    力争群雄:2012年度IT博客大赛100强脱颖而出[通俗易懂]2012年度IT博客大赛于11月20日圆满结束。这一所谓的“海选”阶段为期33天,引无数网友和博主翘首以待,来源包括51CTO、独立个人博客、其他博客服务托管商,以及今年评选新增加的分类如独立博客、学生博客和团队博客等众多博主共同参加了这一角逐,其中100位实力雄厚和人气充盈的博主获得了前100强的殊荣。他们占据了25万张票选中的8成以上份量,并将为2012年度IT博客50…

    2022年7月21日
    10
  • 四种黑盒测试方法_八大心态的总结怎么写

    四种黑盒测试方法_八大心态的总结怎么写一、等价类划分法1.定义2.划分等价类2.1有效等价类2.2无效等价类3.划分等价类的标准4.划分等价类的方法5.设计测试用例6.三角形实例二、边界值分析法1.定义2.与等价划分的区别3.边界值分析方法的考虑4.常见的边界值5.边界值分析6.基于边界值分析方法选择测试用例的原则7.实例说明8、三角形问题的边界值分析测试用例三、错误推测方法1.定义2.错误推测方法的基本思想:四、因果图方法1.定义2.因果图法产生的背景:3.因果图介绍4.因果图概念5.采用因果图法设计测试用例的步.

    2022年10月3日
    0
  • MVC3和MVC4中CRUD操作

    MVC3和MVC4中CRUD操作

    2022年1月23日
    45
  • 如何清理电脑中c盘的垃圾_计算机基本组成

    如何清理电脑中c盘的垃圾_计算机基本组成系统盘,也就是我们常说的C盘!必须要保持足够的存储空间,才能够确保电脑不会运行卡顿,或者出现一些系统性的问题。其实,我们安装系统的时候,C盘最多也就被占用20G左右的空间。但是C盘作为系统盘,电脑运行时所产生的系统缓存文件、垃圾文件以及程序运行文件等等,都会不断的占用C盘的空间,使得C盘越来越小,电脑越用越卡!今天大白菜就和大家分享4招c盘清理方法,让大家的C盘可以腾出更多的空间,保证电脑运行更加…

    2022年8月31日
    3
  • LVS-DR与Keepalived高可用群集「建议收藏」

    LVS-DR与Keepalived高可用群集

    2022年4月3日
    346

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号