PDA

View Full Version : 302 redirect from rss feed to front page: trouble with HTTP Requests


craftkiller
01-31-2008, 01:56 AM
Greetings, I am writing a Linux program under c++ that will eventually download the most recent episode to my mythtv backend (Yes, I deemed this easier than getting mythstream to work under minimyth). I figure ill run it as a cron job every week BUT when I send my http request:
GET /diggnation/feed/xvid-large/ HTTP/1.1\nHost: diggnation.com:80\nFrom: craftkiller@gmail.com\nUser-Agent: CraftCast/1.0\n\n
I get a 302 redirect back:
HTTP/1.1 302 Found
Date: Thu, 31 Jan 2008 01:49:06 GMT
Server: Apache/2.2.6 (Unix) mod_ssl/2.2.6 ra DAV/2 PHP/5.2.4
Location: http://revision3.com/diggnation/diggnation/feed/xvid-large/
Content-Length: 243
Keep-Alive: timeout=2, max=100
Connection: close
Content-Type: text/html; charset=iso-8859-1
Set-Cookie: BIGipServerwww2=2884234705.20480.0000; path=/

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://revision3.com/diggnation/diggnation/feed/xvid-large/">here</a>.</p>
</body></html>


I put the link it sends me into my web browser to check it out and I get the revision 3 front page. Can someone tell me what I'm doing wrong? Even though this is entirely an HTTP issue ill attach my program's source code below (yes I used a c++ socket tutorial example to start it... so if you recognize it then you should remember your n00b days aswell... unless you wrote this tutorial... then you are AWESOME)

#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <iostream>
#include <string>

#define MAX_LINE 1024
#define LINE_ARRAY_SIZE (MAX_LINE+1)

using namespace std;

int main()
{
int socketDescriptor;
unsigned short int serverPort;
struct sockaddr_in serverAddress;
struct hostent *hostInfo;
char buf[LINE_ARRAY_SIZE];

//cout << "Enter server host name or IP address: ";


// gethostbyname() takes a host name or ip address in "numbers and
// dots" notation, and returns a pointer to a hostent structure,
// which we'll need later. It's not important for us what this
// structure is actually composed of.
hostInfo = gethostbyname("revision3.com");
if (hostInfo == NULL) {
cout << "problem interpreting host: " << buf << "\n";
exit(1);
}

cout << "Enter server port number: ";
serverPort = 80;
//cin.get(c); // dispose of the newline

// Create a socket. "AF_INET" means it will use the IPv4 protocol.
// "SOCK_STREAM" means it will be a reliable connection (i.e., TCP;
// for UDP use SOCK_DGRAM), and I'm not sure what the 0 for the last
// parameter means, but it seems to work.
socketDescriptor = socket(AF_INET, SOCK_STREAM, 0);
if (socketDescriptor < 0) {
cerr << "cannot create socket\n";
exit(1);
}

// Connect to server. First we have to set some fields in the
// serverAddress structure. The system will assign me an arbitrary
// local port that is not in use.
serverAddress.sin_family = hostInfo->h_addrtype;
memcpy((char *) &serverAddress.sin_addr.s_addr,
hostInfo->h_addr_list[0], hostInfo->h_length);
serverAddress.sin_port = htons(serverPort);

if (connect(socketDescriptor,
(struct sockaddr *) &serverAddress,
sizeof(serverAddress)) < 0) {
cerr << "cannot connect\n";
exit(1);
}

cout << "\nEnter some lines, and the server will modify them and\n";
cout << "send them back. When you are done, enter a line with\n";
cout << "just a dot, and nothing else.\n";
cout << "If a line is more than " << MAX_LINE << " characters, then\n";
cout << "only the first " << MAX_LINE << " characters will be used.\n\n";

// Prompt the user for input, then read in the input, up to MAX_LINE
// charactars, and then dispose of the rest of the line, including
// the newline character.
char request[] = "GET /diggnation/feed/xvid-large/ HTTP/1.1\nHost: diggnation.com:80\nFrom: craftkiller@gmail.com\nUser-Agent: CraftCast/1.0\n\n";

// Stop when the user inputs a line with just a dot.
//while (strcmp(buf, ".")) {
// Send the line to the server.
if (send(socketDescriptor, request, strlen(request) + 1, 0) < 0) {
cerr << "cannot send data ";
close(socketDescriptor);
exit(1);
}

// Zero out the buffer.
memset(buf, 0x0, LINE_ARRAY_SIZE);

// Read the modified line back from the server.
if (recv(socketDescriptor, buf, MAX_LINE, 0) < 0) {
cerr << "didn't get response from server?";
close(socketDescriptor);
exit(1);
}

cout << "Modified: " << buf << "\n";


//}

close(socketDescriptor);
return 0;
}

joskar
02-01-2008, 05:36 PM
http://revision3.com/diggnation/diggnation/feed/xvid-large/

There's one /diggnation to many, the link should be:

http://revision3.com/diggnation/feed/xvid-large/

Happy coding ;)

craftkiller
02-06-2008, 01:22 AM
yeah that link with the 2 diggnations is being returned by the server... but I think I figured it out, I think I need to put some cookies in there