Discussion:
Proxy Connection fails with Apache HttpClient but succeeds with java.net.URLConnection
Sreyan Chakravarty
2018-07-24 15:20:50 UTC
Permalink
I am on a Windows machine at work and am using HttpClient to make a request
via a web proxy. But the problem is that I keep 407 Authentication required
message.

But if I do the same thing via the RestTemplate of Spring, which uses the
vanilla java.net.URLConnection class, with supplying just the proxy address
and port, it works fine. *It doesn't even need the user name and password
for authentication. *

Why does this work? Why does HttpClient fail?

Doing some digging into the source I made out that HttpClient first opens a
socket to the required address and then reads and writes from that socket.
AFAIK, java.net.URLConnection does not do that.

So my question is what does java.net.URLConnection do differently? What is
the difference between opening a socket.

Also how do I make HttpClient behave like java.net.URLConnection so that I
can avoid the error.

Clearly java.net.URLConnection is doing something right.

Any help or suggestions ?
--
Regards,
Sreyan
Oleg Kalnichevski
2018-07-25 08:17:30 UTC
Permalink
Post by Sreyan Chakravarty
I am on a Windows machine at work and am using HttpClient to make a request
via a web proxy. But the problem is that I keep 407 Authentication required
message.
But if I do the same thing via the RestTemplate of Spring, which uses the
vanilla java.net.URLConnection class, with supplying just the proxy address
and port, it works fine. *It doesn't even need the user name and password
for authentication. *
Why does this work? Why does HttpClient fail?
Doing some digging into the source I made out that HttpClient first opens a
socket to the required address and then reads and writes from that socket.
AFAIK, java.net.URLConnection does not do that.
So my question is what does java.net.URLConnection do differently? What is
the difference between opening a socket.
Also how do I make HttpClient behave like  java.net.URLConnection so
that I
can avoid the error.
Clearly  java.net.URLConnection  is doing something right.
Right or wrong, it uses Windows platform specific authentication code.
HttpClient supports native Windows authentication when running on
Windows family of OSes

http://hc.apache.org/httpcomponents-client-4.5.x/httpclient-win/apidocs
/index.html

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Sreyan Chakravarty
2018-07-25 14:37:08 UTC
Permalink
What is the difference between them? What is the meaning of "Windows
platform specific authentication code" ? What is the authentication
code? Also what is " native Windows authentication " ? Where can I find
more information about this? Any docs?

What is the meaning of authentication code?

Could you please provide more info.
Post by Oleg Kalnichevski
Post by Sreyan Chakravarty
I am on a Windows machine at work and am using HttpClient to make a request
via a web proxy. But the problem is that I keep 407 Authentication required
message.
But if I do the same thing via the RestTemplate of Spring, which uses the
vanilla java.net.URLConnection class, with supplying just the proxy address
and port, it works fine. *It doesn't even need the user name and password
for authentication. *
Why does this work? Why does HttpClient fail?
Doing some digging into the source I made out that HttpClient first opens a
socket to the required address and then reads and writes from that socket.
AFAIK, java.net.URLConnection does not do that.
So my question is what does java.net.URLConnection do differently? What is
the difference between opening a socket.
Also how do I make HttpClient behave like java.net.URLConnection so that I
can avoid the error.
Clearly java.net.URLConnection is doing something right.
Right or wrong, it uses Windows platform specific authentication code.
HttpClient supports native Windows authentication when running on
Windows family of OSes
http://hc.apache.org/httpcomponents-client-4.5.x/httpclient-win/apidocs
/index.html
<http://hc.apache.org/httpcomponents-client-4.5.x/httpclient-win/apidocs/index.html>
Oleg
---------------------------------------------------------------------
--
Regards,
Sreyan
Sreyan Chakravarty
2018-08-03 14:32:07 UTC
Permalink
It worked. Thanks for the help. This example helped me :

https://hc.apache.org/httpcomponents-client-4.5.x/httpclient-win/examples/org/apache/http/examples/client/win/ClientWinAuth.java
Post by Sreyan Chakravarty
What is the difference between them? What is the meaning of "Windows
platform specific authentication code" ? What is the authentication
code? Also what is " native Windows authentication " ? Where can I find
more information about this? Any docs?
What is the meaning of authentication code?
Could you please provide more info.
Post by Oleg Kalnichevski
Post by Sreyan Chakravarty
I am on a Windows machine at work and am using HttpClient to make a request
via a web proxy. But the problem is that I keep 407 Authentication required
message.
But if I do the same thing via the RestTemplate of Spring, which uses the
vanilla java.net.URLConnection class, with supplying just the proxy address
and port, it works fine. *It doesn't even need the user name and password
for authentication. *
Why does this work? Why does HttpClient fail?
Doing some digging into the source I made out that HttpClient first opens a
socket to the required address and then reads and writes from that socket.
AFAIK, java.net.URLConnection does not do that.
So my question is what does java.net.URLConnection do differently? What is
the difference between opening a socket.
Also how do I make HttpClient behave like java.net.URLConnection so that I
can avoid the error.
Clearly java.net.URLConnection is doing something right.
Right or wrong, it uses Windows platform specific authentication code.
HttpClient supports native Windows authentication when running on
Windows family of OSes
http://hc.apache.org/httpcomponents-client-4.5.x/httpclient-win/apidocs
/index.html
<http://hc.apache.org/httpcomponents-client-4.5.x/httpclient-win/apidocs/index.html>
Oleg
---------------------------------------------------------------------
--
Regards,
Sreyan
--
Regards,
Sreyan
Loading...