Full authentication is required to access this resource Unauthorized
来源:互联网 发布:linux配置两个tomcat 编辑:程序博客网 时间:2024/06/06 13:07
在于某银行app对接用户时,对方接口提供了获取accesstoken,方式是通过post进行提交数据,都是基于oauth协议来完成。
例如接口地址:https://test_Id:test_secret@test.com/oauth/authorize
再拿到接口后,肯定要测试一下是否能获取结果,所以就使用了在线post提交请求,模拟获取数据,结果能够成功,想着应该不会有问题,就开发写代码。
但是通过代码时无法获取数据,一直返回401状态,Unauthorized,错误消息:Full authentication is required to access this resource。
不管如何设置,包括请求头部、编码、json、form表单提交等,都是一样的错误,但是在浏览器里模拟就成功了。
返回错误消息:
{"timestamp":1510558350024,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource","path":"/oauth/authorize"}
怎么解决呢?
我们先看一下给的连接地址,此url明显有2个符合(: @),查询了一下,发现其实就是一个账户和密码登陆,而我们在浏览器里操作,浏览器默认会自动解析登陆,那代码如何写呢?
解决办法:
var tokenRequestParams = new SortedDictionary<string, string> { {"type", "authorization"} }; var content = new FormUrlEncodedContent(tokenRequestParams); var handler = new HttpClientHandler { Credentials = new NetworkCredential("test_Id", "test_secret")//账户、密码 }; var httpClient = new HttpClient(handler); var data = httpClient.PostAsync("https://test_Id:test_secret@test.com/oauth/authorize", content);
NetworkCredential:可以在网络中提供一个凭证,只有获得该凭证的用户才能访问相应的服务的权限,关键就是在这个地方。
阅读全文
0 0
- Full authentication is required to access this resource Unauthorized
- Full authentication is required to access this resource
- spring-boot-actuator报错Full authentication is required to access this resource
- curl -X POST http://localhost:8881/bus/refresh Unauthorized Full authentication is required
- unauthorized: authentication required
- Access restriction: The type Resource is not accessible due to restriction on required library
- Access restriction: The type Resource is not accessible due to restriction on required library
- Access restriction: The type Resource is not accessible due to restriction on required library
- Access restriction: The type Resource is not accessible due to restriction on required library
- HTTP Error 401.1 - Unauthorized:Access is denied due to invalid credentials
- Lync 2013 Unauthorized: Access is denied due to a RBAC authorization Failure
- Access restriction: The type 'Resource' is not API (restriction on required library 'G:\JAVA\jdk\lib
- ASP.NET is not authorized to access the requested resource.
- libdpush_v2_3.so:unauthorized access to "libssl.so"
- libdpush_v2_3.so:unauthorized access to "libssl.so"
- javax.mail.MessagingException: 553 authentication is required
- javax.mail.MessagingException: 553 authentication is required
- javax.mail.MessagingException: 553 authentication is required
- Android7.0 BatteryService
- 自动驾驶开源代码
- 2017年11月11日 软件系统架构师考试经验分享
- centos7下openstack安装的部分问题
- 微信分享接口开发所遇到的问题
- Full authentication is required to access this resource Unauthorized
- ldap链接代码
- ip优质供应商
- 预处理元编程
- 现金贷“利滚利”超过高利贷,如何避免“人死债消”的困境?
- 关于spring coud hystrix超时问题
- 运维常见命令(三)-不解压查看bz2日志文件
- 多行文本显示省略号
- cmake+OPENCV3.3 VS2017 安装笔记