连接到 Window Live Oauth 时出现 java.net.MalformedURLException
我正在使用 scribe java API 进行 Oauth 服务,并且能够与 Gmail 和 Facebook 完美配合,但当涉及到 Window live 服务时,我感到震惊。 我遵循的标准代码对于其他服务来说工作得很好。我能够从 window live 获取访问令牌 但是当我尝试访问该服务以获取用户配置文件时,我收到的
java.net.MalformedURLException
是异常日志消息,
org.scribe.exceptions.OAuthException: Problems while creating connection.
org.scribe.model.Request.send(Request.java:71)
org.scribe.model.OAuthRequest.send(OAuthRequest.java:12)
......
......
java.net.MalformedURLException: no protocol: "https://apis.live.net/v5.0/me?access_token=EwAoAq1DBAAUlbRWyAJjK5w968Ru3Cyt%5C%2F6GvwXwAAdfi2SDJuwJlMd29Za96amS5o2UFyXbtnIZglVJKxdimcPb2yYie966goCS2%2ByCjrWBpgUUUphkhYwFyFiN8I2J3pdyg4IQlbG%2BD8U%5C%2F9q5M5iU1q6niqYldYYOyq3ZpNw95l3oFdefQBlnEesequMhHhTVw%2B0ku93xc06lnULgYbVubTWqT8zBzwgHRie93CSDl1wUWQAYe2TzAAk9iIsBvmTmiICdWFrFpZrmpBS3VOec9zdarXuloaXI1IEPA5fDT%2B04RF8uUi1AukmRfjr%2B4C2J8fg8wbRQguMlZNLwG9fleixl2MLcA18ZOkHS%2Bu2eS5BcDYzCfOI8YJ9zf9IGUDZgAACLp7RJwAG8gk%2BAAFtLOh0pYNNGb3AtyjyurJowo014DLmKLLQfjeB0Lz3Nnwd0oBSv0g0qAT8qvdlLlVNyvgg3weqYiR%2BxD%2Bl8kX0SFBX7unVAkiloyqme7D4lNSM25wnJJrmc8wgop5x12MxwtuAOx3IXaNijCkyqtyVRfpU%2BVYv%5C%2FyH5JRuKOEia%2BX00%5C%2FEeWOXOP%5C%2F1yL9zYpRDaBpgOlZ7gBY6Q45buBjaGWsAi4Zg7QSDZeaFkMrIkVaWhhOdpNArXfUnDWAezlLqQZF0Otl8%5C%2F9%2BP3hel0mR7noFaMG0o57kV%2Bnm%2BhzF8LgCZleJCVdxC19ZmhrLM%5C%2FKTTEkAYHQWXhLQAA
java.net.URL.<init>(Unknown Source)
java.net.URL.<init>(Unknown Source)
java.net.URL.<init>(Unknown Source)
org.scribe.model.Request.createConnection(Request.java:81)
org.scribe.model.Request.send(Request.java:62)
org.scribe.model.OAuthRequest.send(OAuthRequest.java:12)
com.raisonne.oauth.action.OAuthCallbackHandlerAction.OtherCallBackHandler(OAuthCallbackHandlerAction.java:101)
com.raisonne.oauth.action.OAuthCallbackHandlerAction.execute(OAuthCallbackHandlerAction.java:50)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:270)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
我不知道 API 出了什么问题,该 API 工作正常,在调试其他应用程序时它创建了相同的 URL 模式,
connection = (HttpURLConnection) new URL(effectiveUrl).openConnection();
这就是API 中抛出异常的行
I am using scribe java API for Oauth service and i am able to work perfectly with Gmail and Facebook but when it comes to Window live service i am strucked.
i am following the standard code whihc is working perfectly fine for other services.i am able to get access token from window live
but when i am trying to access the service to get user profile i am getting
java.net.MalformedURLException
here is the exception log message
org.scribe.exceptions.OAuthException: Problems while creating connection.
org.scribe.model.Request.send(Request.java:71)
org.scribe.model.OAuthRequest.send(OAuthRequest.java:12)
......
......
java.net.MalformedURLException: no protocol: "https://apis.live.net/v5.0/me?access_token=EwAoAq1DBAAUlbRWyAJjK5w968Ru3Cyt%5C%2F6GvwXwAAdfi2SDJuwJlMd29Za96amS5o2UFyXbtnIZglVJKxdimcPb2yYie966goCS2%2ByCjrWBpgUUUphkhYwFyFiN8I2J3pdyg4IQlbG%2BD8U%5C%2F9q5M5iU1q6niqYldYYOyq3ZpNw95l3oFdefQBlnEesequMhHhTVw%2B0ku93xc06lnULgYbVubTWqT8zBzwgHRie93CSDl1wUWQAYe2TzAAk9iIsBvmTmiICdWFrFpZrmpBS3VOec9zdarXuloaXI1IEPA5fDT%2B04RF8uUi1AukmRfjr%2B4C2J8fg8wbRQguMlZNLwG9fleixl2MLcA18ZOkHS%2Bu2eS5BcDYzCfOI8YJ9zf9IGUDZgAACLp7RJwAG8gk%2BAAFtLOh0pYNNGb3AtyjyurJowo014DLmKLLQfjeB0Lz3Nnwd0oBSv0g0qAT8qvdlLlVNyvgg3weqYiR%2BxD%2Bl8kX0SFBX7unVAkiloyqme7D4lNSM25wnJJrmc8wgop5x12MxwtuAOx3IXaNijCkyqtyVRfpU%2BVYv%5C%2FyH5JRuKOEia%2BX00%5C%2FEeWOXOP%5C%2F1yL9zYpRDaBpgOlZ7gBY6Q45buBjaGWsAi4Zg7QSDZeaFkMrIkVaWhhOdpNArXfUnDWAezlLqQZF0Otl8%5C%2F9%2BP3hel0mR7noFaMG0o57kV%2Bnm%2BhzF8LgCZleJCVdxC19ZmhrLM%5C%2FKTTEkAYHQWXhLQAA
java.net.URL.<init>(Unknown Source)
java.net.URL.<init>(Unknown Source)
java.net.URL.<init>(Unknown Source)
org.scribe.model.Request.createConnection(Request.java:81)
org.scribe.model.Request.send(Request.java:62)
org.scribe.model.OAuthRequest.send(OAuthRequest.java:12)
com.raisonne.oauth.action.OAuthCallbackHandlerAction.OtherCallBackHandler(OAuthCallbackHandlerAction.java:101)
com.raisonne.oauth.action.OAuthCallbackHandlerAction.execute(OAuthCallbackHandlerAction.java:50)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:270)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
i am clueless what is going wrong for a API which is working fine as while debugging for other applicaation its creating same URL pattern
connection = (HttpURLConnection) new URL(effectiveUrl).openConnection();
this is the line in API where it throwing the exception
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,这不是使用
HttpURLConnection
的问题,因为:HttpsURLConnection
是HttpURLConnection
的子类型
如果是这样的话,它肯定会抛出类转换
相反,
您传递的 URL,我的猜测是它看起来像这样:
"\"https://..."
(请注意,您有一个前面的" 但不是 URL 中的尾随代码)
First of all, this is not a problem of using
HttpURLConnection
, because:HttpsURLConnection
is a subtype ofHttpURLConnection
If that were the case, it would definitely throw a class cast
exception instead
Check the URL you're passing, my guess is that it looks like this:
"\"https://..."
(Note that you have a preceding"
but not a trailing one on the URL)由于您的 URL 使用“https”协议,因此您必须使用
HttpsURLConnection
类,而不是HttpURLConnection
类。Since your URL uses the "https" protocol, you must use the
HttpsURLConnection
class, not theHttpURLConnection
class.