[英]Using Azure Hybrid Connection to connect to internal Web API
Very new to Azure, and I have an internal web API on an internal address http://internal-server:182/api/policies . Azure的新手,我在内部地址http:// internal-server:182 / api / policies上有一个内部Web API。 I have set up a Hybrid Connection internal-service.servicebus.windows.net. 我已经设置了Hybrid Connection internal-service.servicebus.windows.net。 This is connected and working. 这已连接并且正在工作。
My struggle is getting the C# code working to connect and retrieve the data. 我的奋斗目标是使C#代码能够连接和检索数据。 After a number of days, I have reviewed various articles, videos etc and all seem more advanced than what I am trying to do, which is just call the Web API and read the JSON. 几天后,我查看了各种文章,视频等,它们似乎都比我尝试做的要先进,后者只是调用Web API并读取JSON。 I have tried to simplify the code but receive the error: 我试图简化代码,但收到错误:
401 MalformedToken: Invalid authorization header: The request is missing WRAP authorization credentials.
At present I have the followed code: 目前,我有以下代码:
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;
}
} }
Any help or direction would be much appreciated? 任何帮助或指示将不胜感激? Once this code is working the Web App will be published as an Azure Web App. 此代码运行后,该Web App将作为Azure Web App发布。
Seems that your are not sending the right header. 似乎您没有发送正确的标题。
First suggestion: intercept the call with a proxy like fiddler , to do that add a proxy config to your call to localhost port 8888, after this you can try some request and see the raw http you are sending to the server, you can also modify it until it works, once you have this modify your code until it send the same raw http. 第一个建议:使用诸如fiddler之类的代理拦截该呼叫,以在向本地主机端口8888的呼叫中添加代理配置,此后您可以尝试一些请求并查看要发送到服务器的原始http,也可以修改直到它起作用为止,一旦您修改了代码,直到它发送了相同的原始http。
You can find more info about this here: 您可以在此处找到有关此的更多信息:
Microsoft Azure CreateQueue using Simple REST Client 使用简单REST客户端的Microsoft Azure CreateQueue
https://github.com/ytechie/event-hubs-sas-generator https://github.com/ytechie/event-hubs-sas-generator
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.