gpt4 book ai didi

java - 应用引擎 : Could not verify SSL certificate for URL

转载 作者:行者123 更新时间:2023-11-30 09:17:31 25 4
gpt4 key购买 nike

我正在尝试使用 OAuth 连接到 Intuit Quickbooks,使用他们在 AppEngine (SDK 1.8.4) 上托管的 JAVA API V3。首先,我只是根据他们的说明运行他们的示例代码:http://ippdocs.intuit.com/0025_QuickBooksAPI/0055_DevKits/0201_IPP_Java_DevKit_3.0

它在 TomCat 上运行良好,但是当我调整代码以在 AppEngine 上运行时,出现此错误:

OauthHelper.java 提取,最后一行抛出异常:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;
import oauth.signpost.http.HttpParameters;

[...]
URL url;
url = new URL(signedRequestTokenUrl);
HttpURLConnection httpconnection = (HttpURLConnection) url
httpconnection.setRequestMethod("GET");
httpconnection.setRequestProperty("Content-type", "application/xml");
httpconnection.setRequestProperty("Content-Length", "0");
if (httpconnection != null) {
BufferedReader rd = new BufferedReader(new InputStreamReader(
httpconnection.getInputStream()));
[...]

导致此错误:

javax.net.ssl.SSLHandshakeException: Could not verify SSL certificate for URL: https://oauth.intuit.com/oauth/v1/get_request_token?oauth_signature=VzStL8UcIoDrgKdcU7jJAWaux5Y%3D&oauth_callback=http%3A%2F%2Flocalhost%3A8888%2Faccesstoken.htm&oauth_consumer_key=qyprdulFn7zfTw5ewpZhkPxSo4q27X&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1379761817&oauth_nonce=5706619579888946790
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.convertApplicationException(URLFetchServiceImpl.java:144)
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:43)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.fetchResponse(URLFetchServiceStreamHandler.java:417)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getInputStream(URLFetchServiceStreamHandler.java:296)
at com.intuit.utils.OauthHelper.getRequestTokenSignPost(OauthHelper.java:167)

网址如下:

https://oauth.intuit.com/oauth/v1/get_request_token?oauth_signature=xxxx&oauth_callback=http%3A%2F%2Flocalhost%3A8888%2Faccesstoken.htm&oauth_consumer_key=xxxx&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1379768671&oauth_nonce=-78989043

完全相同的一段代码在 TomCat 7 上完美运行。

路标

我还尝试用以下内容替换 DefaultOAuthConsumer 和 DefaultOAuthProvider:

oauth.signpost.commonshttp.CommonsHttpOAuthProvider;
oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;

,但它会生成完全相同的异常。

有什么想法吗?

最佳答案

在我说我尝试了一些对我来说意义不大但似乎有效的方法之后,立即尝试:

        URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
FetchOptions lFetchOptions = FetchOptions.Builder.validateCertificate();
HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET, lFetchOptions);
HTTPResponse response = fetcher.fetch(request);

对我来说是 FetchOptions.Builder 并明确设置“validateCertificate()”;看看这是否能为您解决问题。

关于java - 应用引擎 : Could not verify SSL certificate for URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18932751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com