3

I'm trying to access an image through a url. The problem is I have to be authenticated via a session id to access the image. I'm trying to get authenticated but I'm getting a 403. Also, how would I add my session id and other information after being authenticated to grab the input stream of the image? Here is my attempt:

CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("https://cloud.openalpr.com/account/login/");
List<NameValuePair> form = new ArrayList<>();
form.add(new BasicNameValuePair("username","user"));
form.add(new BasicNameValuePair("password", "password"));

UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, Consts.UTF_8);
    httpPost.setEntity(entity);
    httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");
httpPost.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X ...");
CloseableHttpResponse response = httpClient.execute(httpPost);
dur
  • 15,689
  • 25
  • 79
  • 125
Bob Miller
  • 31
  • 3

1 Answers1

0

This server requires others fields: csrfmiddlewaretoken and next. See in below image extracted from site https://cloud.openalpr.com/account/login/

enter image description here

In this way you must does:

List<NameValuePair> form = new ArrayList<>();
form.add(new BasicNameValuePair("username","user"));
form.add(new BasicNameValuePair("password", "password"));
form.add(new BasicNameValuePair("csrfmiddlewaretoken", "xxxxxxx"));
form.add(new BasicNameValuePair("next", ""));
Aristofanio Garcia
  • 1,103
  • 8
  • 13