[英]Azure web app service to call onpremise WEB API using HttpClient using hybrid connection manager
[英]Using Azure Hybrid Connection to connect to internal Web API
Azure的新手,我在內部地址http:// internal-server:182 / api / policies上有一個內部Web API。 我已經設置了Hybrid Connection internal-service.servicebus.windows.net。 這已連接並且正在工作。
我的奮斗目標是使C#代碼能夠連接和檢索數據。 幾天后,我查看了各種文章,視頻等,它們似乎都比我嘗試做的要先進,后者只是調用Web API並讀取JSON。 我試圖簡化代碼,但收到錯誤:
401 MalformedToken: Invalid authorization header: The request is missing WRAP authorization credentials.
目前,我有以下代碼:
using (var client = new HttpClient())
{
var url = "http://internal-service.servicebus.windows.net";
var tp = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "<key goes here>");
var token = tp.GetWebTokenAsync(url, string.Empty, true, TimeSpan.FromHours(1))
.GetAwaiter()
.GetResult();
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("ServiceBusAuthorization", token);
var response = client.GetAsync("/api/policies").Result;
string res = "";
using (HttpContent content = response.Content)
{
// ... Read the string.
Task<string> result = content.ReadAsStringAsync();
res = result.Result;
Label1.Text = res;
}
}
任何幫助或指示將不勝感激? 此代碼運行后,該Web App將作為Azure Web App發布。
似乎您沒有發送正確的標題。
第一個建議:使用諸如fiddler之類的代理攔截該呼叫,以在向本地主機端口8888的呼叫中添加代理配置,此后您可以嘗試一些請求並查看要發送到服務器的原始http,也可以修改直到它起作用為止,一旦您修改了代碼,直到它發送了相同的原始http。
您可以在此處找到有關此的更多信息:
使用簡單REST客戶端的Microsoft Azure CreateQueue
https://github.com/ytechie/event-hubs-sas-generator
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.