I am trying to query "http://www.idmypill.com/api/id/" api and the JSON string I am receiving back is {"results":[],"success":false,"errors":null}
This is my service handler class:
public String makeServiceCall(String url, int method,
String api, byte[] pillImage)
{
try {
// http client
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
// Checking http request method type
if (method == POST)
{
android.os.Debug.waitForDebugger();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("data = api_key", api);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("files = image", pillImage);
entity = builder.build();
Log.d("Entity", entity.toString());
httpPost.setEntity(entity);
Log.d("post", httpPost.toString());
httpResponse = httpClient.execute(httpPost);
Log.d("params", httpResponse.getParams().toString());
}
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
The python example the website gives is:
# highly suggested to use the requests package
# http://www.python-requests.org/en/latest/
import requests
# read in the image and construct the payload
image = open("example.jpg").read()
data = {"api_key": "KH8hdoai0wrjB0LyeA3EMu5n4icwyOQo"}
files = {"image": open("example.jpg")}
# fire off the request
r = requests.post("http://www.idmypill.com/api/id/",
data = data,
files = files)
# contents will be returned as a JSON string
print r.content
Somehow my format for posting must be wrong or is it possible they specifically want a .jpg image instead of a byte array? I am not familiar with Python and have been struggling with this problem for over a week now so any help would be much appreciated.