我在 IBM Watson Studio 中创建了一个 ML 模型,并将该模型部署到 Web 服务中。我需要创建一个 java 程序来发送输入并从该 Web 服务检索输出。
我检查了我所有的连接凭据,这没有问题。
我在这里使用的代码与 watson-studio 中给出的代码(在部署部分下的实现选项卡中)相同,但我仍然遇到错误。
程序停在这一行
scoringBuffer = new BufferedReader(new InputStreamReader(scoringConnection.getInputStream()));
检查此代码:-
package Original;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
public class Iris_Deployment {
public static void main(String[] args) {
// NOTE: you must manually construct wml_credentials hash map below
// using information retrieved from your IBM Cloud Watson Machine Learning Service instance.
Map<String, String> wml_credentials = new HashMap<String, String>()
{{
put("url", "https://eu-gb.ml.cloud.ibm.com");
put("username", "my-username-comes-here");
put("password", "my-password-comes-here");
}};
String wml_auth_header = "Basic " +
Base64.getEncoder().encodeToString((wml_credentials.get("username") + ":" +
wml_credentials.get("password")).getBytes(StandardCharsets.UTF_8));
String wml_url = wml_credentials.get("url") + "/v3/identity/token";
HttpURLConnection tokenConnection = null;
HttpURLConnection scoringConnection = null;
BufferedReader tokenBuffer = null;
BufferedReader scoringBuffer = null;
米脂
相关分类