Solved

HTTP headers

Posted on 2000-03-17
10
136 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

762 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

18 Experts available now in Live!

Get 1:1 Help Now