i'm trying to request a GET via HTTPS trough a Proxy. The Proxy answers with 400:Bad Request. I sniffed the data with wireshark and i have seen, that the headers are not set. Because of security, i replaced some Values with <> Brackets. Can anybody help?

This is a part of my implementation:

```
String urlString = ctx.getUrl();
HttpHost target;
CloseableHttpClient httpclient;
HttpClientContext localContext;
try
{
     CredentialsProvider credsProvider = new BasicCredentialsProvider();
     int proxyport = Integer.parseInt(ctx.getProxyPort());

     credsProvider.setCredentials(
         new AuthScope(<MyProxyUrl>, <MyProxyPort>),
         new UsernamePasswordCredentials(<MyProxyUser>, <MyProxyPassword>));

     httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();

     target = new HttpHost(urlString, 443, "https");
     HttpHost proxy = new HttpHost(<MyProxyUser>, <MyProxyPassword>);

     RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
     request = new HttpGet("/");
     request.setURI(new URI(urlString));
     //this method sets different header
     HttpProperty.setHeaders(request, ctx);
     request.setConfig(config);

     HttpResponse response = httpclient.execute(target, request);

```

I have traced the headers in the request with and printed name/value with the output below:

```
     Header[] headers = request.getAllHeaders();

```

Header Name:Proxy-Connection

Header Value:close

Header Name:Proxy-Authorization

Header Value:Basic 

Header Name:User-Agent

Header Value: MyDevice

Header Name:Accept

Header Value:text/html

At least this is the response:
Content length responesCode: 0 400

From Wireshark sniffing i found, that the headers which are defintly inside the request are not set when sending CONNECT. 

I attached this picture:

![Wireshark Trace](https://i.stack.imgur.com/UzgA0.png)

**EDIT:
Thank you Damian Nikodem,
but i found the solution.
The first request is always sent without user headers.
I changed two things, and the proxy authorization works:
request = new HttpGet(urlString);
HttpResponse response = httpclient.execute(request);**