Log in or register to post comments

Issues with Unauthorized Response

September 16, 2016 - 2:00pm #3

Hey all,

I'm trying to setup a basic cloud recognition page for a demo and have been frustrated so far by a fairly persistent "unauthorized" response.

I already have a working application that performs CRUD operations on image targets in the cloud db and I've used the VWS code I already have for that as a jumping-off point.

Given the documentation and what I already know about my (working) code I can conclude that my issue stems from one of two sources:

  1. formatting the image as 8bit binary
  2. the signature builder from the example code

Here is the method I'm using for formatting the image:

public byte[] extractBytes (String img) throws IOException {

    File fi = new File(img);

    byte[] fileContent = Files.readAllBytes(fi.toPath());

    return fileContent;


And here is the HTTP Request from the sample code (modified slightly):

private String postTarget(PrintWriter outResult, String path, String accessKey, String secretKey)

   throws URISyntaxException, ClientProtocolException, IOException, JSONException {

     HttpPost postRequest   = new HttpPost();

     HttpClient client      = new DefaultHttpClient();

     postRequest.setURI(new URI(url+"/query"));

        JSONObject object      = new JSONObject();

        object.put("image", URLEncoder.encode(new String(extractBytes(path)), "UTF-8"));

        StringEntity reqEntity = new StringEntity(object.toString(), ContentType.MULTIPART_FORM_DATA);


        JSONObject response = new JSONObject();

     setHeaders(postRequest, accessKey, secretKey, outResult);

        try {

          ResponseHandler<String> responseHandler = new BasicResponseHandler();

          String responseBody = client.execute(postRequest, responseHandler);

          response.put("res", responseBody);

        } catch (Exception e) {

          response.put("ex", e);


     return response.toString(3);


Unfortunately, the only response I've been able to get is: { "ex": "org.apache.http.client.HttpResponseException: Unauthorized" }


Any guidance would be GREATLY appreciated; thanks!

Issues with Unauthorized Response

September 19, 2016 - 2:27pm #2


The most likely reason that I can think of for an authentication error is that you may be using the wrong keys. Client Access Keys are used to make queries to the Cloud Reco Web API and Server Access Keys are used to make requests to the VWS API.


Issues with Unauthorized Response

September 20, 2016 - 7:01am #1

It seems you're correct; switching the keys resolved the authentication issues. I'm still seeing a bad request error but that looks like a separate issue.



Log in or register to post comments