无法连接到gateway.watsonplatform.net:443 [英] Cannot Connect to gateway.watsonplatform.net:443
问题描述
我正在尝试运行示例Java应用程序,
i am trying to run the sample java application as described on
我已经能够正确设置我的自由服务器,并且能够使用我的帐户在bluemix服务器上创建一个应用程序.当我尝试在Eclipse中运行示例代码时,我可以看到watson q& a应用程序界面.但是当我按下询问"按钮时,我得到了
i have been able to set up my liberty server properly and i have been able to create an app on the bluemix server with my account. When i try to run the sample code in Eclipse, i can see the watson q&a app interface. But when i hit the Ask button, i get
Error: Connect to gateway.watsonplatform.net:443 [gateway.watsonplatform.net/23.246.237.54] failed: Connection timed out: connect
除了输入服务网址和用户名和密码的值外,我没有对代码进行任何更改.
i have not made any changes to the code except putting in the values for the url of my service and the username and password.
我需要设置另一个系统属性吗?
Is there another system property i need to set?
manifest.yaml
applications:
- services:
- question_and_answer
name: myDumbApp
path: webApp.war
memory: 512M
另外,当我运行命令时
cf marketplace -s question_and_answer
我明白了
service plan description free or paid
question_and_answer_free_plan Beta free
那是正确的吗?
试用QuestionAndAnswer API
import java.util.HashMap;
import java.util.Map;
import com.ibm.watson.developer_cloud.personality_insights.v2.PersonalityInsights;
import com.ibm.watson.developer_cloud.personality_insights.v2.model.Profile;
import com.ibm.watson.developer_cloud.question_and_answer.*;
import com.ibm.watson.developer_cloud.question_and_answer.v1.QuestionAndAnswer;
import com.ibm.watson.developer_cloud.question_and_answer.v1.model.QuestionAndAnswerDataset;
public class PersonalityInsightsExample {
public static void main(String[] args) {
QuestionAndAnswer qas = new QuestionAndAnswer();
qas.setUsernameAndPassword("uName", "Pass");
QuestionAndAnswerDataset qd = new QuestionAndAnswerDataset("TRAVEL");
/*
PersonalityInsights service = new PersonalityInsights();
service.setUsernameAndPassword("uName", "Pass");
String myProfile = "Call me Ishmael. Some years ago-never mind how long "
+ "precisely-having little or no money in my purse, and nothing "
+ "particular to interest me on shore, I thought I would sail about "
+ "a little and see the watery part of the world. It is a way "
+ "I have of driving off the spleen and regulating the circulation. "
+ "Whenever I find myself growing grim about the mouth; whenever it "
+ "is a damp, drizzly November in my soul; whenever I find myself "
+ "involuntarily pausing before coffin warehouses, and bringing up "
+ "the rear of every funeral I meet; and especially whenever my "
+ "hypos get such an upper hand of me, that it requires a strong "
+ "moral principle to prevent me from deliberately stepping into "
+ "the street, and methodically knocking people's hats off-then, "
+ "I account it high time to get to sea as soon as I can.";
Profile profile = service.getProfile(myProfile);
*/
qas.setDataset(qd);
System.out.println( qas.ask("How to get cold?"));
}
}
但我仍然得到
SEVERE: IOException
org.apache.http.conn.HttpHostConnectException: Connection to https://gateway.watsonplatform.net refused
请注意,当我跑步
System.out.println(qas.getEndPoint());
我明白了
https://gateway.watsonplatform.net/question-and-answer-beta/api
这与我的代码中的导入一致吗?
is that consistent with the imports in my code?
推荐答案
确保您具有服务凭证,并且没有使用Bluemix username
和password
.
Make sure you have service credentials and you are not using your Bluemix username
and password
.
由于您要使用Personality-Insights,我建议您首先从Main类开始,然后尝试看看您是否具有有效的凭据
Since you want to use Personality-Insights I would suggest you to first start with a Main class and try to see that you have valid credentials
- Download the Watson Developer Cloud Java SDK v1.1.1.
- In eclipse, create a java project(no web, plain java).
- Create a file and call it
PersonalityInsightsExample.java
. Copy the code below.
import java.util.HashMap; 导入java.util.Map; 导入com.ibm.watson.developer_cloud.personality_insights.v2.model.Profile;
import java.util.HashMap; import java.util.Map; import com.ibm.watson.developer_cloud.personality_insights.v2.model.Profile;
公共类PersonalityInsightsExample {
public class PersonalityInsightsExample {
public static void main(String[] args) {
PersonalityInsights service = new PersonalityInsights();
service.setUsernameAndPassword("<username>", "<password>");
String myProfile = "Call me Ishmael. Some years ago-never mind how long "
+ "precisely-having little or no money in my purse, and nothing "
+ "particular to interest me on shore, I thought I would sail about "
+ "a little and see the watery part of the world. It is a way "
+ "I have of driving off the spleen and regulating the circulation. "
+ "Whenever I find myself growing grim about the mouth; whenever it "
+ "is a damp, drizzly November in my soul; whenever I find myself "
+ "involuntarily pausing before coffin warehouses, and bringing up "
+ "the rear of every funeral I meet; and especially whenever my "
+ "hypos get such an upper hand of me, that it requires a strong "
+ "moral principle to prevent me from deliberately stepping into "
+ "the street, and methodically knocking people's hats off-then, "
+ "I account it high time to get to sea as soon as I can.";
Profile profile = service.getProfile(myProfile);
System.out.println(profile);
}
}
替换username
和password
.
作为Java应用程序运行.
Run it as a Java Application.
If you still get an error following the steps above then try opening a browser and going to: https://gateway.watsonplatform.net/personality-insights/api/v2/profile, you should get a password prompt.
这篇关于无法连接到gateway.watsonplatform.net:443的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!