Overview
Features
Download
Documentation
Community
Add-Ons & Services

HTTPS request using Net Library

Please post support and help requests here.

HTTPS request using Net Library

Postby vermaamitabh » 11 Dec 2007, 02:29

Hi,
I need to send a https request (e.g. https://service.mydomain.com/wservice/abc?param1¶m2) to web service which returns a xml response. It is a well formed URL without any explicit port mentioned in it.
I am using the following code to create HTTPClient session

Code: Select all

url=https://service.mydomain.com/wservice/abc?param1¶m2;
URI uri(url);
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest: :HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.sendRequest(req);


When HTTPClientSession is created with "uri.getPort", by default it takes port 443 as connection port to server and I Get "connection reset by peer" message as response and if I remove uri.getPort and use only getHost, it takes port 80 as default.
Is there anyway that I can get it working without explicit port information as I dont have it.

The same url works fine, if sent by WebBrowser in form of URL (https://service.mydomain.com/wservice/abc?param1¶m2).

Any help is highly appreciated.
Thanks
vermaamitabh
 
Posts: 3
Joined: 08 Dec 2007, 03:56

Re: HTTPS request using Net Library

Postby guenter » 11 Dec 2007, 08:08

HTTPClientSession does not support HTTPS, only plain HTTP.
To use HTTPS, you'll have to use the HTTPSClientSession class from the NetSSL library.

Alternatively, you can use the HTTPSessionFactory class:

Code: Select all

#include "Net/HTTPSessionFactory.h"
#include "Net/HTTPSessionInstantiator.h"
#include "Net/HTTPSSessionInstantiator.h"
...
HTTPSessionFactory sf;
sf.registerProtocol("http", new HTTPSessionInstantiator);
sf.registerProtocol("https", new HTTPSSessionInstantiator);

URI uri("https://service.mydomain.com/wservice/abc?param1¶m2");
std::auto_ptr pSession(sf.createClientSession(uri));
HTTPRequest req(HTTPRequest: :HTTP_GET, path, HTTPMessage::HTTP_1_1);
pSession->sendRequest(req);
...


Similarly, there is also the URIStreamOpener class, which also supports HTTPS, as long as you do a

Code: Select all

HTTPSStreamFactory::registerFactory();


HTH,

Günter
guenter
 
Posts: 1111
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HTTPS request using Net Library

Postby vermaamitabh » 12 Dec 2007, 23:31

Hi Gunter,
Many thanks for your reply. When I try to use above mentioned code, I get following linker error:
"fatal error LNK1104: cannot open file 'PocoNetSSLd.lib"
I have searched all the directories but couldn't find such file. Do I miss some thing to install or where can I get it?
Thanks,
-Amitabh

vermaamitabh
 
Posts: 3
Joined: 08 Dec 2007, 03:56

Re: Re: HTTPS request using Net Library

Postby alex » 13 Dec 2007, 00:07

> Hi Gunter,
> Many thanks for your reply. When I try to use above mentioned code, I get following linker error:
> "fatal error LNK1104: cannot open file 'PocoNetSSLd.lib"
> I have searched all the directories but couldn't find such file. Do I miss some thing to install or where can I get it?

Check out SVN, or download the appropriate poco-*-ssl archive from sourceforge.
Also, read the NetSSL HowTo

Alex
alex
 
Posts: 1104
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: HTTPS request using Net Library

Postby vermaamitabh » 13 Dec 2007, 02:58

Hello Alex,

thanks for pointing out to "How-to". It works now and I can compile the program. Unfortunately again i got stuck and getting no idea.
When I execute the follwoing code with "HTTPS" uri

std::auto_ptr pSession(sf.createClientSession(uri));
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
pSession->sendRequest(req);
send request fails with following exception.
.........................................................................................
NULL pointer: _pInstance [in file "c:pocoutilincludepocoutilapplication.h", line 422]
Null pointer: _pInstance in file "c:pocoutilincludepocoutilapplication.h", line 422
.............................................................................................
Good thing is that when I use it with HTTP uri, it works fine. In above code, I am creating pSession for HTTPClientSession as HTTPSessionFactory (sf) returns only HTTPCientSession pointer type so I assume that it may work for HTTPS (in your sample code, you have used same method but cannot get compiled due to missing type declaration).
Could you please direct me to send https request successfully?
Thanks for your help anc coopeartion.

vermaamitabh
 
Posts: 3
Joined: 08 Dec 2007, 03:56


Return to Support

Who is online

Users browsing this forum: No registered users and 4 guests

cron