我需要在CloudSight上进行httppost重新构成图像识别目的。我有:
BASE URL https://api.cloudsight.ai/v1/images
Headers: Content-Type application/json
Authorization Cloudsight API_KEY
它说:使用HTTP POST请求在端点/图像上发送图像,并使用多部分编码或Base64编码的数据参数发送图像。URL:http://docs.cloudsight.apiary.io/#reference/0/images-collection/send-an-image-for-isenefication?console = 1到目前为止,我已经做到了:
private class HTTPPOSTReguest extends AsyncTask<String, Void, String> {
ProgressDialog dialog;
String result = "";
@Override
protected void onPreExecute() {
}
@Override
protected String doInBackground(String... params) {
try {
HttpResponse response = null;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(BASE_URL);
httppost.addHeader("Content-Type", "application/json");
httppost.addHeader("Authorization", "CloudSight buEA_pC6K7FXT60inM2eUQ");
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("images", encodedImage));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(httppost);
int responseCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
if (entity != null) {
String responseBody = EntityUtils.toString(entity);
result = responseBody;
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
buth似乎可以成功地进行。有人可以提供建议
我在浏览此过程时注意到了几件事。在第二个摘要中,授权标题读取:
Cloudsight API_KEY
代替CloudSight API_KEY
不确定这只是快速错别字还是代码中是否是在代码中。在代码示例中,有一个行读数:
HttpPost httppost = new HttpPost("https://api.cloudsightapi.ai");
应该是:
HttpPost httppost = new HttpPost("https://api.cloudsight.ai/v1/images");
给我们一个镜头,让我们知道它的发展!