Sponsored Content
Top Forums Programming Need help regarding HTTP parsing Post 302343304 by rakesh_01 on Wednesday 12th of August 2009 06:12:42 AM
Old 08-12-2009
Thanks for the reply.I eventually came up with this program as a result of a few modifications

Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>

#define MAXBUFF 99999

int main(int argc, char** argv)
{
         struct sockaddr_in servaddr;
         struct hostent *hp;
         int sock_id,i=1;
         int len;
         char buffer[MAXBUFF],message[9999];
         char msglen;
         char request[] = "GET /en/index.html HTTP/1.1\r\nHost:bandvalley.com\r\nUser-Agent:HTMLGET 

1.1\r\n\r\n";

                                       //Get a socket

        if((sock_id = socket(AF_INET, SOCK_STREAM, 0)) == -1)
           {
                fprintf(stderr,"Couldn't get a socket.\n");
                exit(EXIT_FAILURE);
           }

        else
        {
               fprintf(stderr,"Got a socket.\n");
        }

                                       //book uses bzero which my man pages say is deprecated
                                       //the man page said to use memset instead. :-)
        memset(&servaddr,'\0',sizeof(servaddr));

                                      //get address for bandvalley.com
        if((hp = gethostbyname("174.36.228.144")) == NULL)
        {
            fprintf(stderr,"Couldn't get an address.\n");
            exit(EXIT_FAILURE);
        }
        else
        {
           fprintf(stderr,"Got an address.\n");
        }

                                       //bcopy is deprecated also, using memcpy instead
        memcpy((char *)&servaddr.sin_addr.s_addr, (char *)hp->h_addr, hp->h_length);

                                        //fill int port number and type
        servaddr.sin_port = htons(80);
        servaddr.sin_family = AF_INET;

                                        //make the connection
        if(connect(sock_id, (struct sockaddr *)&servaddr, sizeof(servaddr)) != 0)
        {
          fprintf(stderr, "Connection error.\n");
        }
        else
        {
           fprintf(stderr,"Got a connection!!!\n");
        }

                                          //NOW THE HTTP PART!!!

                                          //send the request

      send(sock_id,request,strlen(request),0);



     //read the response
     if(i==1)
     {
      do
      {
      len=recv(sock_id,buffer,MAXBUFF-1,0);
      buffer[len]='\0';
      printf("%s",buffer);
      }while(i=1);
     }
     else
    {
      return 0;
      }
    }

but it still doesnt get the last two lines of code.I know my mistake also.
i's value never changes.But I dont know the exact size of the page source so how do I correct this error.

Any advices on this???
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HTTP Query Request & Parsing returned XML output

I have a PERL script from which I need to make a HTTP request to Web Servlet (Essentially a URL with variables and values like &Variable1=AAAAAA&Variable2=BBBBBBBBB&Variable3=CCCCCCC). The Web servlet returns an XML result which needs to be parsed for the contents of the result within the program.... (15 Replies)
Discussion started by: jerardfjay
15 Replies

2. UNIX for Advanced & Expert Users

http

how to downloaad a web page using http server (0 Replies)
Discussion started by: krishnavel
0 Replies

3. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

4. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

5. Linux

Dynamic HTTP

hi guys, please i would like to know how to cache dynamic websites, on squid 3.1 thanks (1 Reply)
Discussion started by: zazoo
1 Replies

6. Programming

sending http url through http socket programming..

hi am senthil am developing a software to send and receive SMS using HTTP connection first of all am forming a URL and sending that URL to a remote server using my Client Program i send that url through Socket(using Send() Function) if i send more than one URL one by one using the same... (0 Replies)
Discussion started by: senkerth
0 Replies

7. Shell Programming and Scripting

sending http url through http socket programming..

hi am senthil am developing a software to send and receive SMS using HTTP connection first of all am forming a URL and sending that URL to a remote server using my Client Program i send that url through Socket(using Send() Function) if i send more than one URL one by one using the same... (4 Replies)
Discussion started by: senkerth
4 Replies

8. Shell Programming and Scripting

Parsing the http post request

Hi, I am trying to write a shell script to parse the post request data that it received to a xml file. Below is the post request data that script is receiving. -----------------------------7dd2339190c8e Content-Disposition: form-data; name="param1" 1... (2 Replies)
Discussion started by: jdp
2 Replies

9. Web Development

HTTP Headers Reference: HTTP Status-Codes

Hypertext Transfer Protocol -- HTTP/1.1 for Reference - HTTP Headers 10 Status Code Definitions Each Status-Code is described below, including a description of which method(s) it can follow and any metainformation required in the response. (1 Reply)
Discussion started by: Neo
1 Replies

10. Shell Programming and Scripting

awk script to find time difference between HTTP PUT and HTTP DELETE requests in access.log

Hi, I'm trying to write a script to determine the time gap between HTTP PUT and HTTP DELETE requests in the HTTP Servers access log. Normally client will do HTTP PUT to push content e.g. file_1.txt and 21 seconds later it will do HTTP DELETE, but sometimes the time varies causing some issues... (3 Replies)
Discussion started by: Juha
3 Replies
EKG2-REMOTE(1)						      General Commands Manual						    EKG2-REMOTE(1)

NAME
ekg2-remote - remote User Interface for EKG2 SYNOPSIS
ekg2-remote [OPTIONS] REMOTE-ENDPOINT DESCRIPTION
ekg2-remote is a program which provides a remote user interface to an EKG2 instance that uses the "remote" plugin. It connects to EKG2 via a socket, and lets you use the program as if it was running locally. The motivation behind this program was to be able to use EKG2 on a low performance machine with limited memory and CPU resources. OPTIONS
-c, --charset=CHARSET forces the charset name to use, -p, --password=PASSWORD sets the password, -T, --test=FRONTEND runs in test mode (for debugging), using FRONTEND user interface (default is ncurses), -F, --frontend=FRONTEND uses FRONTEND user interface (default is ncurses), -m, --no-mouse does not load mouse support, -U, --unicode forces unicode support, -h, --help displays a help message, -v, --version displays program version and exits ENDPOINT specifies the EKG2 instance to connect to. The following are accepted: tcp:address:port cleartext TCP/IP connection to given address and port tcps:address:port SSL-encrypted TCP/IP connection to given address and port udp:address:port UDP/IP connection to given address and port unix:socket-path local (UNIX) connection to given socket-path pipe:fifo-path local (pipe) connection to given fifo-path. Currently unsupported. SEE ALSO
ekg2(1). The full documentation for ekg2 is maintained as a Docbook manual. See http://ekg2.org/ekg2book/ for an online version. User Commands 2008-03-05 EKG2-REMOTE(1)
All times are GMT -4. The time now is 05:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy