我正在尝试在我的应用程序中构建聊天机器人。但我无法将 Microsoft bot 与 Direct line Rest API 连接到应用程序,下面是我连接 bot 的代码。它给了我 FileNotFoundException,但我真的不知道该怎么做。有人帮助我吗?
private String startConversation() {
String primaryToken = "ABC";
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
String UrlText = " https://directline.botframework.com/api/tokens/conversation";
URL url = null;
String responseValue = "";
try {
url = new URL(UrlText);
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection urlConnection = null;
try {
String basicAuth = "Bearer " + primaryToken;
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Authorization", basicAuth);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json");
} catch (IOException e) {
e.printStackTrace();
}
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
responseValue = readStream(in);
} catch (Exception e) {
e.printStackTrace();
} finally {
urlConnection.disconnect();
}
return responseValue;//returns the conversationID and token
}
例外 :
W/System.err: java.io.FileNotFoundException: https://directline.botframework.com/api/tokens/conversation
07-21 11:37:44.636 23256-23256/com.directlineex.brsingh.directlineandroidexample W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:206)
07-21 11:37:44.636 23256-23256/com.directlineex.brsingh.directlineandroidexample W/System.err: at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
07-21 11:37:44.636 23256-23256/com.directlineex.brsingh.directlineandroidexample W/System.err: at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25