在我的 .net core Web api 项目中,我想使用外部 API,以便获得预期的响应。
我注册和使用 HttpClient 的方式如下。在启动中,我添加了以下代码,称为命名类型 httpclient 方式。
services.AddHttpClient<IRecipeService, RecipeService>(c => {
c.BaseAddress = new Uri("https://sooome-api-endpoint.com");
c.DefaultRequestHeaders.Add("x-raay-key", "123567890754545645gggg");
c.DefaultRequestHeaders.Add("x-raay-host", "sooome-api-endpoint.com");
});
Run Code Online (Sandbox Code Playgroud)
除此之外,我还有 1 个服务,我在其中注入了 HttpClient。
public class RecipeService : IRecipeService
{
private readonly HttpClient _httpClient;
public RecipeService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<List<Core.Dtos.Recipes>> GetReBasedOnIngAsync(string endpoint)
{
using (var response = await _httpClient.GetAsync(recipeEndpoint))
{
// ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
创建 httpClient 时,如果我将鼠标悬停在对象本身上,则基本 URI/标头会丢失,并且我不明白为什么会发生这种情况。如果有人能透露一些信息,我将不胜感激:)
第一次更新
该服务正在如下所示的控制器之一中使用。该服务由 DI 注入,然后将相对路径解析为该服务(我假设我已经将基本 URL 存储在客户端中)也许我做错了?
namespace ABC.Controllers
{
[ApiController]
[Route("[controller]")] …
Run Code Online (Sandbox Code Playgroud) c# asp.net-web-api dotnet-httpclient asp.net-core-webapi httpclientfactory
I'm trying to send an email with Gmail account. I was able to send emails with yahoo, however, it doesn't work anymore, for some unknown reason. Which i posted a question about that as well, but not response.
In this instance, i'm trying to connect to a gmail account so that I can send emails, but with no luck, it fails after the Connect.
It connects successfully but doesn't authenticate at all, although I have the right credentials.
This is …
我正在尝试使用 Jsonconverter 反序列化 json 字符串。我拥有 json 中的所有值,我还想提一下,特定的 json 是从 swagger 生成的,因此当我向 API 发送有效负载时,它会将其映射到对象模型中。
但是,当我尝试将其反序列化为同一个对象时,一切都是空的。我做错了什么?
这就是我反序列化它的方式
EmailUrlDto testEmailUrlDto = JsonConvert.DeserializeObject<EmailUrlDto>(jsonString);
Run Code Online (Sandbox Code Playgroud)
JSON格式
{
"templateUrl": "https://some.blob.url.here.com",
"paramsHtml": [
{
"name": "{{miniAdmin}}",
"value": "Heyth is Admin!"
},
{
"name": "{{cliBuTree}}",
"value": "I`m a treeee!"
}
],
"from": "string",
"subject": "string",
"message": "string",
"isHtmlBody": true,
"recipients": [
{
"recipient": "some.name@lol.com"
}
],
"cCRecipients": [
{
"recipient": "string"
}
],
"bCCRecipients": [
{
"recipient": "string"
}
]
}
Run Code Online (Sandbox Code Playgroud)
电子邮件网址
public class EmailUrlDto : EmailDto
{
[Required] …
Run Code Online (Sandbox Code Playgroud) 仅当某些内容为真时,我才尝试将类应用于组件标记。
我如何将该主机转变为条件主机,以便我在需要时应用所需的类?
@Component({
selector: 'k-sidebar',
host: {
class: '{{isChanged}}'
},
templateUrl: './ng-k-side-bar.component.html',
encapsulation: ViewEncapsulation.None
})
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用使用 $(美元符号)的 c# 功能创建一个字符串。结果将是这样的{{name}}。我唯一捕捉到了名字然后我想做一些像 EG 的事情
$"{{name}}"
所以我的问题是如何捕捉整个事情?在字符串中包括括号?EG“{{name}}”?似乎我不能用 $ 符号做到这一点。
这是我试过的
emailHtmlBuilder.Replace($"{{paramsHtml.Name}}", HttpUtility.HtmlEncode(paramsHtml.Value))};
Run Code Online (Sandbox Code Playgroud)
该模板有一些占位符 EG {{thisIsPlaceholder}}。我想用 EG 杯替换整个 {{thisIsPlaceholder}}
还是我应该使用正则表达式来创建该字符串?
我正在尝试使用T-SQL从Visual Studio 2017查询数据库。查询是:
Select *
From table
Where columnname like '0%'
Run Code Online (Sandbox Code Playgroud)
错误消息如下:
消息207,级别16,状态1,第1行
无效的列名称'0%'。
由于某种原因,控制台中的like子句为灰色,与其他子句不同,它不是蓝色。
我想获取所有字节以0开头的记录,例如:
SELECT JobFileName
FROM JobImages
WHERE JobFileName LIKE "0%"
Run Code Online (Sandbox Code Playgroud) c# ×3
angular ×1
database ×1
email ×1
json ×1
json.net ×1
jsonconvert ×1
mailkit ×1
smtp ×1
smtp-auth ×1
smtpclient ×1
sql ×1
sql-server ×1
t-sql ×1