使用简单REST客户端的Microsoft Azure CreateQueue [英] Microsoft Azure CreateQueue using Simple REST Client

查看:43
本文介绍了使用简单REST客户端的Microsoft Azure CreateQueue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Azure云上创建队列.我有一个Azure帐户,名称空间并使用Service Bus.由于某些限制,我需要使用RAW GET/PUT请求进行操作,因此我使用的是

I'm trying to create a queue on Azure cloud. I've an Azure account, namespace and using Service Bus. Due to some restrictions I need to do it using RAW GET/PUT requests so I'm using Simple REST Client.

这些是REST客户端字段中提到的值:

These are the values mentioned in REST client fields:

URL

https://mynamespace-ns.servicebus.windows.net/

方法

PUT

标题

PUT/testqueue?timeout = 30 HTTP/1.1

PUT /testqueue?timeout=30 HTTP/1.1

x-ms-date:2015年9月25日星期五,格林尼治标准时间

x-ms-date: Fri, 25 Sep 2015 03:16:12 GMT

x-ms-version:2009-09-19

x-ms-version: 2009-09-19

授权:SharedKey mynamespace-ns:oucfev8CXZPMsli4t7iZJ + nlC0fUwasyPH5OdSqi9po =

Authorization: SharedKey mynamespace-ns:oucfev8CXZPMsli4t7iZJ+nlC0fUwasyPH5OdSqi9po=

主机:mynamespace-ns.servicebus.windows.net

Host: mynamespace-ns.servicebus.windows.net

内容长度:0

这是我生成授权密钥的方式:

This is how I'm generating the Authorization key:

HmacSha256编码字符串"PUT \ n \ n \ n \ n0 \ n \ n \ n \ n \ n \ n \ n \ nx-ms-date:Fri,25 Sep 2015 03:16:12 GMT \具有密钥的nx-ms-version:2009-09-19 \ n/mynamespace-ns是从Azure Portal的连接信息"页复制的SharedAccessKey.之后,Base64Encode结果字符串.

HmacSha256 encoding the string "PUT\n\n\n\n0\n\n\n\n\n\n\n\nx-ms-date:Fri, 25 Sep 2015 03:16:12 GMT\nx-ms-version:2009-09-19\n/mynamespace-ns" with secret key is the SharedAccessKey copied from Connection Information page on Azure Portal. After that Base64Encode the resulted string.

每次发送请求时,都会收到以下响应:

Every-time I send the request I got the following response:

401 MalformedToken:无效的授权标头:该请求缺少WRAP授权凭证.TrackingId:8d52cae0-0dba-470d-8db2-3e76d4fd4d0b_G27,TimeStamp:9/25/2015 9:45:17 AM

401MalformedToken: Invalid authorization header: The request is missing WRAP authorization credentials. TrackingId:8d52cae0-0dba-470d-8db2-3e76d4fd4d0b_G27,TimeStamp:9/25/2015 9:45:17 AM

任何人都可以告诉我我所缺少的内容还是我做错了什么吗?

Can anyone please tell what I'm missing or am I doing something wrong?

推荐答案

请求必须在请求标头中附加访问令牌.使用Azure服务总线时,您需要从azure访问控制服务中获取令牌.找到此页面...

The request has to have an access token attached in the request headers. When using Azure service bus, you need to get a token from the azure access control service. Found this page...

Azure访问令牌模式

您不需要使用SDK来完成所有这些操作,就像我在Android程序中所做的一样.

You do not need to use SDK to do all this as I am doing the same from an Android program.

编辑...

您必须将其调整为所使用的任何语言.

You'll have to adjust this to whatever language you are using.

首先获取令牌...

URL acsUrl = new URL("https://yournamespace-sb.accesscontrol.windows.net/WRAPv0.9/");
URL realm = new URL("http://yournamespace.servicebus.windows.net");
httpConn = (HttpURLConnection) acsUrl.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setUseCaches(false);
httpConn.setDoInput(true);
httpConn.setDoOutput(true);
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

String body = "wrap_name=" + URLEncoder.encode(AdminConstants.ISSUER, "UTF-8") + 
"&wrap_password=" + URLEncoder.encode(AdminConstants.ISSUER_SECRET, "UTF-8") +
"&wrap_scope=" + URLEncoder.encode(realm,  "UTF-8");
byte[] postBytes = body.getBytes();
httpConn.setRequestProperty("Content-Length", Integer.toString(postBytes.length));
httpConn.setRequestProperty("Expect", "100-continue");
httpConn.setRequestProperty("Accept", "*/*");

/* Fire the request here */

String[] responseProperties = response.toString().split("&");
String[] tokenProperty = responseProperties[0].split("=");
String token = URLDecoder.decode(tokenProperty[1], "UTF-8");

由于我正在访问服务总线,而您正在创建队列,因此您的境界将有所不同.

Your realm will be different since I am accessing service bus and you are creating queues.

最后,当您致电创建队列时,您必须像这样在发帖请求中包含令牌...

Finally when you make your call to create the queue you will have to include the token in your post request like this...

httpConn.setRequestProperty("Authorization", "WRAP access_token=\"" + getAcsToken() + "\"");

这篇关于使用简单REST客户端的Microsoft Azure CreateQueue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆