连接到 Window Live Oauth 时出现 java.net.MalformedURLException

发布于 2024-12-18 04:00:22 字数 7228 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断念 2024-12-25 04:00:22

首先,这不是使用HttpURLConnection的问题,因为:

  1. HttpsURLConnectionHttpURLConnection

    的子类型

  2. 如果是这样的话,它肯定会抛出类转换
    相反,

您传递的 URL,我的猜测是它看起来像这样:

"\"https://..." (请注意,您有一个前面的 " 但不是 URL 中的尾随代码)

First of all, this is not a problem of using HttpURLConnection, because:

  1. HttpsURLConnection is a subtype of HttpURLConnection

  2. 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)

猫烠⑼条掵仅有一顆心 2024-12-25 04:00:22

由于您的 URL 使用“https”协议,因此您必须使用 HttpsURLConnection 类,而不是 HttpURLConnection 类。

Since your URL uses the "https" protocol, you must use the HttpsURLConnection class, not the HttpURLConnection class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文