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)
上一篇 2025年10月9日 上午9:15
下一篇 2025年10月9日 上午9:43


相关推荐

  • Eclipse语言包安装

    Eclipse语言包安装Eclipse 语言包安装

    2026年3月18日
    1
  • C语言对Excel操作

    C语言对Excel操作C 语言对 Excel 操作

    2026年3月26日
    2
  • 如何通过 User-Agent 识别百度蜘蛛

    如何通过 User-Agent 识别百度蜘蛛如果有大量的百度蜘蛛抓取网站就需要注意了:有可能是其他爬虫伪造百度蜘蛛恶意抓取网站。如果遇到这种情况,这时候就需要查看日志来确定是不是真正的百度蜘蛛(baiduspider)。搜索引擎蜘蛛、用户访

    2022年7月3日
    56
  • mysql longtext 查询_mysql中longtext存在大量数据时,会导致查询很慢?

    mysql longtext 查询_mysql中longtext存在大量数据时,会导致查询很慢?一个表,1.5w条数据,字段:id,name,content,last_update_timeid,自定义主键name,varchar类型content是longtext类型,last_update_time为datetime类型,不为空content当中是文本和代码等,平均长度在20k+。case1:selectid,namefromtorderbylast_update_tim…

    2022年5月14日
    52
  • 门面模式php,门面模式 php

    门面模式php,门面模式 php门面模式 php 门面模式 Facade 又称外观模式 用于为子系统中的一组接口提供一个一致的界面 门面模式定义了一个高层接口 这个接口使得子系统更加容易使用 引入门面角色之后 用户只需要直接与门面角色交互 用户与子系统之间的复杂关系由门面角色来实现 从而降低了系统的耦 classCamera publicfuncti var dump 开 publicfun

    2026年3月16日
    1
  • goland激活码2021_最新在线免费激活

    (goland激活码2021)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月25日
    64

发表回复

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

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