My output usually is something like:
Second Half New Way: /finance
First Half: Google
Google = 74.125.47.10574.125.47.10674.125.47.14774.125.47.9 974.125.47.
10374.125.47.104
GET /finance HTTP/1.1
Host: Google
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Date: Fri, 04 Nov 2011 02:02:48 GMT
Expires: Fri, 04 Nov 2011 02:02:48 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked
but every now and then the program will actually spit back some actual html code of the page. how come i only get the actual html source some of the time?
Code:/* * File: webClient.c * Author: Adam * * Created on November 3, 2011, 1:26 AM */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> /* * */ int main(int argc, char** argv) { char arg[500]; char firstHalf[500]; char secondHalf[500]; char request[1000]; struct hostent *server; struct sockaddr_in serveraddr; int port = 80; int tcpSocket; strcpy(arg, argv[1]); int i; for (i = 0; i < strlen(arg); i++) { if (arg[i] == '/') { strncpy(firstHalf, arg, i); firstHalf[i] = '\0'; break; } } strncpy(secondHalf, arg + i, strlen(arg) - i); secondHalf[strlen(arg) - i] = '\0'; printf("\nSecond Half New Way: %s", secondHalf); printf("\nFirst Half: %s", firstHalf); tcpSocket = socket(AF_INET, SOCK_STREAM, 0); if (tcpSocket < 0) printf("\nError opening socket"); server = gethostbyname(firstHalf); if (server == NULL) { printf("gethostbyname() failed\n"); } else { printf("\n%s = ", server->h_name); unsigned int j = 0; while (server -> h_addr_list[j] != NULL) { printf("%s", inet_ntoa(*(struct in_addr*)(server -> h_addr_list[j]))); j++; } } printf("\n"); bzero((char *) &serveraddr, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serveraddr.sin_addr.s_addr, server->h_length); serveraddr.sin_port = htons(port); if (connect(tcpSocket, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) < 0) printf("\nError Connecting"); bzero(request, 1000); sprintf(request, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", secondHalf, firstHalf); printf("\n%s", request); if (send(tcpSocket, request, strlen(request), 0) < 0) fprintf(stderr, "Error with send()"); bzero(request, 1000); recv(tcpSocket, request, 999, 0); printf("%s", request); close(tcpSocket); return (EXIT_SUCCESS); }



1Likes
LinkBack URL
About LinkBacks



