views:

429

answers:

2

Hello,

I have been playing with the Poco Net library for some time, it is quite nice. Very convenient and easy to understand.

I was able to set a proxy address, and it is saying 407 Proxy authorization required, properly. I figured that

HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
req.setCredentials(scheme, authInfo);

I tried values like "basic", "plaintext" in scheme, and "user:password" in authInfo. It doesn't seem to work. Google isn't helping.

Has anyone done this using Poco Net before? Or is the usage obvious and I'm not able to get it to work because of my ignorance towards proxy authentication in general? Please advice.

EDIT: After some more playing around, I think the setCredentials function is used when the remote server is expecting authentication information to login. I have not been able to find a way to do proxy authentication using Poco Net libraries. I was able to set the proxy server and port though. This is what I would have if there was just a proxy server without authentication:

HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.setProxy("host", port);
session.sendRequest(req);

Need help.

EDIT: Based on the solution suggested by @StackedCrooked, I tried setting proxy authentication details to the request header before making the request, and in another approach found on the internet, I set proxy auth details only after making an initial request and a 407 error comes, and then making the request again. Both methods kept on giving the same 407 error. My current code looks like this:

HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.setProxy("10.7.128.1", 8080);
req.set("Proxy-Authentication", "Basic bGVlbGE6bGVlbGExMjM=");
session.sendRequest(req);
A: 

I haven't used this myself, but have you looked at the HTTPBasicCredentials class? It wraps up the call to req.setCredentials via its authenticate method. You would end up with something along the lines of:

HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
HTTPBasicCredentials cred("user", "password");
cred.authenticate(req);
Steve Beedie
Just tried. Isn't working. I think HTTPBasicCredentials is required when the remote server is expecting basic authentication information. Now I think even the setCredentials function that I tried initially is also not meant for this purpose.
Sahasranaman MS
+1  A: 

You probably need to add the Proxy Authorization field to the HTTP headers. Poco's HTTPRequest class doesn't have a dedicated method for this. However, since it inherits the NameValueCollection class publicly you can set it like this:

req.set("Proxy-Authorization" , "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");

Where QWxhZGRpbjpvcGVuIHNlc2FtZQ== is the base64 encoded version of "Aladdin:open sesame".

A lot of these problems become easier once you learn a little about the HTTP protocol. I am now mostly preaching to myself :)

StackedCrooked
I've been trying this in various ways, its always giving the same 407 error. Please see the edit in the question.
Sahasranaman MS
Yeah, I can't help you more than this because my knowledge on this subject is kind of limited as well. I hope you found a solution by now (or that you will find one soon!).
StackedCrooked