【发布时间】:2018-05-03 03:45:09
【问题描述】:
我正在尝试通过 url 访问图像。问题是我必须通过会话 ID 进行身份验证才能访问图像。我正在尝试通过身份验证,但我得到了 403。另外,在通过身份验证后如何添加会话 ID 和其他信息以获取图像的输入流?这是我的尝试:
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);
【问题讨论】:
标签: java http authentication httpclient