我正在尝试在我的应用中构建聊天机器人。但我无法将Microsoft bot与Direct line Rest API连接到应用程序,下面是我连接机器人的代码。它给了我FileNotFoundException,但我真的不知道该怎么做。有人帮助我吗?
[MvxFragment(typeof(MainViewModel), Resource.Id.content_frame, true)]
public class SecondFragment : BaseFragment<SecondViewModel>, View.IOnTouchListener
{
private void DoSwipe(string swipeText)
{
if (swipeText.Equals("LEFT"))
{
FragmentManager.BeginTransaction()
.SetCustomAnimations(Resource.Animation.slide_from_left, Resource.Animation.slide_from_right)
.Replace(Resource.Id.content_frame,ThirdFragment.NewInstance(null))
.Commit();
}
if (swipeText.Equals("RIGHT"))
{
...
}
ViewModel.SwipeView(swipeText);
}
}
例外:
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
}