Overview
Features
Download
Documentation
Community
Add-Ons & Services

Weird HTTP problem

Please post support and help requests here.

Weird HTTP problem

Postby rbock » 12 Aug 2008, 10:12

Hi,

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,

Roland

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"
#include
#include

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("http://lufthansa.de/");

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

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

    return 0;
}

 
rbock
 
Posts: 7
Joined: 30 May 2008, 14:05
Location: Germany

Re: Weird HTTP problem

Postby guenter » 12 Aug 2008, 15:31

Hi,

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

GET http://lufthansa.de/ HTTP/1.1


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,

Günter

guenter
 
Posts: 1165
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron