Weird HTTP problem

Please post support and help requests here.
Posts: 7
Joined: 30 May 2008, 14:05
Location: Germany

Weird HTTP problem

Postby rbock » 12 Aug 2008, 10:12


I am facing a weird HTTP problem (at least in my eyes). The following code shows a status code of 403, although every other method I tried (browsers, wget, libwww, and even poco-1.3.2-ssl/NetSSL_OpenSSL/samples/download/src/download.cpp) follows a 302 redirect and yields some reasonable content.

Why isn't the status code 302? Any ideas?

Thank you very much in advance,


Code: Select all

#include "Poco/URI.h"
#include "Poco/SharedPtr.h"
#include "Poco/Exception.h"
#include "Poco/Net/HTTPClientSession.h"
#include "Poco/Net/HTTPSessionFactory.h"
#include "Poco/Net/HTTPSessionInstantiator.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h"

using Poco::URI;
using Poco::SharedPtr;
using Poco::Net::HTTPSessionInstantiator;
using Poco::Net::HTTPSessionFactory;
using Poco::Net::HTTPClientSession;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPResponse;
using std::auto_ptr;

int main()
    URI uri("");

    auto_ptr<HTTPClientSession> clientSession(HTTPSessionFactory::defaultFactory().createClientSession(uri));
    HTTPRequest request(HTTPRequest::HTTP_GET, uri.toString());
    HTTPResponse response;

    std::cerr << "Status code for " << uri.toString() << ": "<< (int) response.getStatus() << std::endl;

    return 0;


Posts: 1190
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Weird HTTP problem

Postby guenter » 12 Aug 2008, 15:31


you are passing uri.toString() to the HTTPRequest object, which will result in the following HTTP request being sent to the server:

Code: Select all


which is the reason for the 403.
Instead of uri.toString(), use uri.getPath().

Furthermore, HTTPClientSession does not automatically follow a redirect, so you'll have to do that manually. For how to code that, see HTTPStreamFactory::open in Net/src/HTTPStreamFactory.cpp.

Best regards,


Return to “Support”

Who is online

Users browsing this forum: No registered users and 1 guest