6

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);
Sahas
  • 10,637
  • 9
  • 41
  • 51
  • Could you put a testcase on codepad.org or something? I'd love to try it against my proxy. – joshperry Aug 29 '09 at 00:37
  • 1
    I believe the correct header, as @StackedCrooked suggested, is "Proxy-Authorization" rather than "Proxy-Authentication". Is your actual code using the correct one? – Steve Beedie Sep 04 '09 at 00:17

2 Answers2

2

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
  • 34,653
  • 44
  • 154
  • 278
  • I've been trying this in various ways, its always giving the same 407 error. Please see the edit in the question. – Sahas Aug 28 '09 at 06:29
  • 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 Sep 04 '09 at 22:18
  • Apart from basic authentication there are other authentications - digest, NTLM, passport etc. WinHTP does this for you (http://msdn.microsoft.com/en-us/library/windows/desktop/aa383144(v=vs.85).aspx). I would be curious to see if poco c++ (or any other library) can do the same. – quixver Nov 12 '12 at 23:02
1

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
  • 945
  • 7
  • 12
  • 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. – Sahas Aug 25 '09 at 12:06
  • 1
    This works... the other answer doesn't (manually Base64Encoding using the poco encoder). – Homer6 Jul 24 '12 at 21:03