gpt4 book ai didi

c# - Sitecore-Web Api 用户认证

转载 作者:行者123 更新时间:2023-11-30 20:24:34 26 4
gpt4 key购买 nike

我只想将 sitecore 数据发送给经过身份验证的用户..如何将 HttpWebRequest 对象传递给 webclient 的 DownloadString 函数....DownloadString 不能将 HttpWebRequest 作为参数。我正在关注此链接 Sitecore 7.2 - Item Web API-User Authentication

var client = new WebClient();

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://gyldendal.local/-/item/v1/?sc_itemid={110D8759F-DEA9-42EA-9C1C-8A5DF7E70EF9}&sc_database=master");

request.Headers["X-Scitemwebapi-Username"] = "admin";
request.Headers["X-Scitemwebapi-Password"] = "b";
var apiResponse = client.DownloadString(request);
dynamic jsonResponse = JObject.Parse(apiResponse);

最佳答案

...这是一种使用 Web API 框架实现的方法;只是因为我是异步的粉丝。

using (var client = new HttpClient())
{
var request = new HttpRequestMessage
{
RequestUri = new Uri("..."),
Method = HttpMethod.Get
};

request.Headers.Add("X-Scitemwebapi-Username", "sitecore\admin");
request.Headers.Add("X-Scitemwebapi-Password", "b");

var response = await client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
var responseString= await response.Content.ReadAsStringAsync();
...
}
}

关于c# - Sitecore-Web Api 用户认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26347030/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com