Solved

HTTP headers

Posted on 2000-03-17
10
138 Views
Last Modified: 2010-04-15
Is the any info out there to fully describe (syntax) requests, like GET etc. ?
0
Comment
Question by:haast
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 1

Expert Comment

by:ntdragon
ID: 2630752
what do you mean something like help for the get command
or you want to know how the get command is build???
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 2630856
RFC 2068
0
 

Expert Comment

by:sylphe
ID: 2631453
Hello,

http://www.rfc.net

rfc 1945, rfc 2068, rfc 2616
0
 

Author Comment

by:haast
ID: 2632139
sylphie and ozo

Sorry yes I am aware of the RFC's, my ill asked question refers to the building of requests as ntdragon guessed. For instance this is how IE5 builds the request to expert exchange about page.

GET /info/about.htm HTTP/1.1

Now if I do something like this :

iaHost.s_addr = inet_addr("www.experts-exchange.com");
lpHostEntry = gethostbyname("www.experts-exchange.com");      
..
fill in address struct, create socket, connect socket ETC.
..
char HttpRequest[]= "GET /info/about.htm\r\n";

nRet = send(Socket, HttpRequest, strlen(HttpRequest), 0);

All works fine, but if I send the EXACT string that IE sends .... (I have verified this by monitoring the TCP/IP port as it transmits data)

char HttpRequest[]= "GET /info/about.htm HTTP/1.1\r\n";

it does not work.

So I want an answer of why it works for IE5 and not me.


0
 
LVL 84

Expert Comment

by:ozo
ID: 2632174
It seems to work for me.
What error do you get?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:haast
ID: 2632878
ozo, I get no response from the server with this!!

void main()
{
WSADATA wsaData;
WORD wVersionRequested = MAKEWORD(1,1);
int      nRet;
char      HttpRequest[] = "GET /info/about.htm HTTP/1.1\r\n";
char szSndBuffer[2048];
char szRecBuffer[2048];

nRet = WSAStartup(wVersionRequested, &wsaData);
if (nRet)
{
WSACleanup();
return;
}
      
if (wsaData.wVersion != wVersionRequested)
{
WSACleanup();
return;
}

IN_ADDR            iaHost;
LPHOSTENT      lpHostEntry;
iaHost.s_addr = inet_addr("www.experts-exchange.com");
lpHostEntry = gethostbyname("www.experts-exchange.com");      
if (lpHostEntry == NULL)
{
PRINTERROR("gethostbyname()");
return;
}
      
SOCKET      Socket;      
Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

if (Socket == INVALID_SOCKET)
{
return;
}

LPSERVENT lpServEnt;
SOCKADDR_IN saServer;

lpServEnt = getservbyname("http", "tcp");
if (lpServEnt == NULL)
saServer.sin_port = htons(80);
else
saServer.sin_port = lpServEnt->s_port;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
nRet = connect(Socket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN));

if (nRet == SOCKET_ERROR)
{
closesocket(Socket);
return;
}
      
sprintf(szSndBuffer, "%s", HttpRequest);
nRet = send(Socket, szSndBuffer, strlen(szSndBuffer), 0);
if (nRet == SOCKET_ERROR)
{
closesocket(Socket);      
return;
}

while(1)
{
nRet = recv(Socket, szRecBuffer, sizeof(szRecBuffer), 0);
if (nRet == SOCKET_ERROR)
{
break;
}
if (nRet == 0)
break;

fwrite(szRecBuffer, nRet, 1, stdout);
}
closesocket(Socket);
WSACleanup();
}



BUT if I use below all is OK !! (and I would live with that except that why does the above work for Microsoft and not me) ??

char      HttpRequest[] = "GET /info/about.htm\r\n";


What
0
 

Author Comment

by:haast
ID: 2632884
oops,

Print error Macro

#define PRINTERROR(s)      \
            fprintf(stderr,"\n%: %d\n", s, WSAGetLastError())
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2633399
i think that the get func automaticlly adds the "get" so if you"ll put  "get" by yourself it won't make any sense

no i don't know the answer to your question but i think that i have an idea how can you find out

write a prog that listen on port 8080<the port dosn't meter it should be more then 1000>
and when it got a connection it read from the client the data it sends and print it

and the second prog will try to get the url from the net<using the func GET> and set a proxi for it
127.0.0.1 and port 8080

run this two on the same come and the first prog will print the request as it made by the func GET
0
 
LVL 3

Expert Comment

by:Iexpert
ID: 2635814
Try HTTP/1.0 instead of HTTP/1.1 as version 1.1 has
issues with keeping connections open for multiple
requests etc.

Also try it without the \r\n at the end.
0
 

Author Comment

by:haast
ID: 2657638
I have figured this out,

sylphe PLEASE collect your points.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I validate a simple fgets() statement in C programming? 15 135
Which version of C should I use when Perl is too slow? 13 173
how to understand recursion 12 218
Problem to ASCII 1 166
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now