Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 651

码神/OpenAuth.Core

forked from 李玉宝/OpenAuth.Core
Paused
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (2)
Tags (3)
master
dev
1.4
1.3
1.2
master
Branches (2)
Tags (3)
master
dev
1.4
1.3
1.2
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (2)
Tags (3)
master
dev
1.4
1.3
1.2
HttpHelper.cs 6.64 KB
Copy Edit Raw Blame History
李玉宝 authored 2018年06月05日 15:07 +08:00 . Infrastructure commit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
namespace Infrastructure
{
/// <summary>
/// http请求类
/// </summary>
public class HttpHelper
{
private HttpClient _httpClient;
private string _baseIPAddress;
/// <param name="ipaddress">请求的基础IP,例如:http://192.168.0.33:8080/ </param>
public HttpHelper(string ipaddress = "")
{
this._baseIPAddress = ipaddress;
_httpClient = new HttpClient { BaseAddress = new Uri(_baseIPAddress) };
}
/// <summary>
/// 创建带用户信息的请求客户端
/// </summary>
/// <param name="userName">用户账号</param>
/// <param name="pwd">用户密码,当WebApi端不要求密码验证时,可传空串</param>
/// <param name="uriString">The URI string.</param>
public HttpHelper(string userName, string pwd = "", string uriString = "")
: this(uriString)
{
if (!string.IsNullOrEmpty(userName))
{
_httpClient.DefaultRequestHeaders.Authorization = CreateBasicCredentials(userName, pwd);
}
}
/// <summary>
/// Get请求数据
/// /// <para>最终以url参数的方式提交</para>
/// <para>yubaolee 2016年3月3日 重构与post同样异步调用</para>
/// </summary>
/// <param name="parameters">参数字典,可为空</param>
/// <param name="requestUri">例如/api/Files/UploadFile</param>
/// <returns></returns>
public string Get(Dictionary<string, string> parameters, string requestUri)
{
if (parameters != null)
{
var strParam = string.Join("&", parameters.Select(o => o.Key + "=" + o.Value));
requestUri = string.Concat(ConcatURL(requestUri), '?', strParam);
}
else
{
requestUri = ConcatURL(requestUri);
}
var result = _httpClient.GetStringAsync(requestUri);
return result.Result;
}
/// <summary>
/// Get请求数据
/// <para>最终以url参数的方式提交</para>
/// </summary>
/// <param name="parameters">参数字典</param>
/// <param name="requestUri">例如/api/Files/UploadFile</param>
/// <returns>实体对象</returns>
public T Get<T>(Dictionary<string, string> parameters, string requestUri) where T : class
{
string jsonString = Get(parameters, requestUri);
if (string.IsNullOrEmpty(jsonString))
return null;
return JsonHelper.Instance.Deserialize<T>(jsonString);
}
/// <summary>
/// 以json的方式Post数据 返回string类型
/// <para>最终以json的方式放置在http体中</para>
/// </summary>
/// <param name="entity">实体</param>
/// <param name="requestUri">例如/api/Files/UploadFile</param>
/// <returns></returns>
public string Post(object entity, string requestUri)
{
string request = string.Empty;
if (entity != null)
request = JsonHelper.Instance.Serialize(entity);
HttpContent httpContent = new StringContent(request);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return Post(requestUri, httpContent);
}
/// <summary>
/// 提交字典类型的数据
/// <para>最终以formurlencode的方式放置在http体中</para>
/// <para>李玉宝于2016年07月20日 19:01:59</para>
/// </summary>
/// <returns>System.String.</returns>
public string PostDicObj(Dictionary<string, object> para, string requestUri)
{
Dictionary<string, string> temp = new Dictionary<string, string>();
foreach (var item in para)
{
if (item.Value != null)
{
if (item.Value.GetType().Name.ToLower() != "string")
{
temp.Add(item.Key, JsonHelper.Instance.Serialize(item.Value));
}
else
{
temp.Add(item.Key, item.Value.ToString());
}
}
else {
temp.Add(item.Key, "");
}
}
return PostDic(temp, requestUri);
}
/// <summary>
/// Post Dic数据
/// <para>最终以formurlencode的方式放置在http体中</para>
/// <para>李玉宝于2016年07月15日 15:28:41</para>
/// </summary>
/// <returns>System.String.</returns>
public string PostDic(Dictionary<string, string> temp, string requestUri)
{
HttpContent httpContent = new FormUrlEncodedContent(temp);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
return Post(requestUri, httpContent);
}
public string PostByte(byte[] bytes, string requestUrl)
{
HttpContent content = new ByteArrayContent(bytes);
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return Post(requestUrl, content);
}
private string Post(string requestUrl, HttpContent content)
{
var result = _httpClient.PostAsync(ConcatURL(requestUrl), content);
return result.Result.Content.ReadAsStringAsync().Result;
}
/// <summary>
/// 把请求的URL相对路径组合成绝对路径
/// <para>李玉宝于2016年07月21日 9:54:07</para>
/// </summary>
private string ConcatURL(string requestUrl)
{
return new Uri(_httpClient.BaseAddress, requestUrl).OriginalString;
}
private AuthenticationHeaderValue CreateBasicCredentials(string userName, string password)
{
string toEncode = userName + ":" + password;
// The current HTTP specification says characters here are ISO-8859-1.
// However, the draft specification for the next version of HTTP indicates this encoding is infrequently
// used in practice and defines behavior only for ASCII.
Encoding encoding = Encoding.GetEncoding("utf-8");
byte[] toBase64 = encoding.GetBytes(toEncode);
string parameter = Convert.ToBase64String(toBase64);
return new AuthenticationHeaderValue("Basic", parameter);
}
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

千星项目OpenAuth.Net基于.Net Core 2.1的快速开发框架。基于经典领域驱动设计的权限管理及快速开发框架,源于Martin Fowler企业级应用开发思想及最新技术组合(.net core、EF core、AutoFac、WebAPI、Swagger、Json.Net等)。 已成功在docker/jenkins中实施。核心模块包括:组织机构、角色用户、权限授权、表单设计、工作流等。它的架构精良易于扩展,是中小企业的首选。
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/dotcpp/OpenAuth.Core.git
git@gitee.com:dotcpp/OpenAuth.Core.git
dotcpp
OpenAuth.Core
OpenAuth.Core
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /