Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

jquery - 在对Azure IOT HUB的Ajax调用上未收到针对未授权的错误401的WWW身份验证标头(No WWW-Authenticate header received for Error 401 Not Authorised on Ajax call to Azure IOT HUB)

I am trying to send a POST request to a service side endpoint on the Azure IOTHUB.

(我试图将POST请求发送到Azure IOTHUB上的服务端终结点。)

I can make this request using cURL without issue from the Azure CLI and my local machine, so the SaS token authentication clearly works.

(我可以使用cURL发出此请求,而Azure CLI和我的本地计算机不会发出任何问题,因此SaS令牌身份验证显然可以正常工作。)

but I get this error

(但是我得到这个错误)

401 (Unauthorized)

(401(未经授权))

my code is

(我的代码是)

 $.ajax({ url: 'https://mydevice.azure-devices.net/twins/mydevice/methods?api-version=2018-06-30', type: 'POST', authorization: 'SharedAccessSignature .......', contentType: 'application/json', methodName: 'reboot', payload: '', responseTimeoutInSeconds: 15 }); 

The 401 error indicates that the wrong authentication method is being used, and should be accompanied by a WWW-Authenticate header.

(401错误表示使用了错误的身份验证方法,并且应随附WWW-Authenticate标头。)

I'm using Fiddler to capture traffic and I don't seem to be getting this header, so I can't even tell what type of authentication is expected.

(我正在使用Fiddler捕获流量,但似乎没有得到此标头,因此我什至无法确定预期的身份验证类型。)

I'm using SaS Token that succeeds with cURL.

(我正在使用随cURL成功的SaS令牌。)

The Browser no longer enforces CORS rules, so the lack of CORS support on the IOTHUB shouldn't be an issue and I've tried proxying via an open proxy.

(浏览器不再强制执行CORS规则,因此IOTHUB上缺少CORS支持应该不是问题,我已经尝试通过开放式代理进行代理。)

So my question is why am I still getting this error?

(所以我的问题是为什么我仍然会收到此错误?)

I am pretty new to this and to be honest I'm not even sure I'm asking the right questions here, so please let me know if I'm way off in the way I'm thinking about this.

(我对此很陌生,说实话,我什至不确定在这里问的是正确的问题,所以请让我知道我是否在考虑这一问题。)

Any advice much appreciated

(任何建议,不胜感激)

  ask by Martin translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...