我正在尝试在我的android应用程序中使用cloudsight.ai api,使用来自url的图像,来自mashape平台的cloudsight.ai api
当我构建应用程序时没有问题,但是当我运行它并单击按钮时它崩溃了。
这是使用 unirest 库的请求代码:
try {
HttpResponse<JsonNode> sent = Unirest.post("https://camfind.p.mashape.com/image_requests")
.header("X-Mashape-Key", "key")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept", "application/json")
.field("image_request[language]", "en")
.field("image_request[locale]", "en_US")
.field("image_request[remote_image_url]", img)
.asJson();
req_body=sent.getBody().toString();
} catch (UnirestException e) {
}
这里是响应代码:
try {
JSONObject json = new JSONObject(req_body);
token = json.getString("token");
} catch (JSONException e) {
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
String res_path = "https://camfind.p.mashape.com/image_responses/" + token;
try {
HttpResponse<JsonNode> response = Unirest
.get(res_path)
.header("X-Mashape-Key", "key")
.header("Accept", "application/json")
.asJson();
result=response.getBody().toString();
} catch (UnirestException e) {
}
Toast.makeText(Main3Activity.this,result,Toast.LENGTH_SHORT).show();
}
如何解决这个问题呢?