asp.net core razor 远程请求 认证Basic auth 模式 body传递 json

浪淘沙2年前后端297
private readonly HttpClient _httpClient;    public RemoteRequestService(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }
 #region 全部退款

 // 设置目标 URL
 string url = "https://xxxx.com/api/Pay/Refund";

 // Basic Auth 用户名和密码
 string Username = "xxx";
 string Password = "xxxx@";
 // 创建 Basic Authentication 的值
 string basicAuth = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{Username}:{Password}"));

 // 准备请求体
 string data = "{\"OutTradeNo\": \""+ OutTradeNo + "\"}";
 var jsonContent = new StringContent(data, Encoding.UTF8, "application/json");


 // 使用 Furion 的远程请求功能
 var authToken = Encoding.ASCII.GetBytes($"{Username}:{Password}");
 _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken));
 // 发起 POST 请求
 var response = await _httpClient.PostAsync(url, jsonContent);
 // 确保请求成功
 response.EnsureSuccessStatusCode();

 var Rn = await response.Content.ReadAsStringAsync();

 #endregion


相关文章

asp.net core指定运行端口 如:http://localhost:5002

网站根目录新建:hosting.json输入:{   "urls": "http://localhost:5002" }...

asp.net core webapi 调用furion 的webapi json接口

/// <summary> /// 根据学校读取支付科次 /// </summary> /// <returns>&l...

asp.net core sqlsugar 复制插入并返回新id

var result = await _db.Ado.GetScalarAsync("insert into qy_gw(gwmc...

asp.net core Aspose.Words 文本换行

using Aspose.Words;// 替换换行符为 Word 中的换行符var placeholders = new&nbs...

查看ubuntu 是否正确安装asp.net core 8.0

dotnet --list-sdks如果您看到列出的.NET Core 8.0 SDK版本,则表明.NET Core 8.0已正确安装。...

asp.net core 绑定下拉

   public List<SelectListItem> zplx { get; set; }  [BindProperty]  public...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。