Archived

This topic is now archived and is closed to further replies.

HTTP-request- NEED HELP - please

This topic is 5303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Gurus // and code junkies i need your help i wrote a little programm to receive html files from a specific url for example www.google.com my problem is the http request: sprintf (command, "GET %s HTTP/1.0\nHost: %s\n\n",file,host); /* send */ bytes_sent = send (sock, command, strlen (command), 0); i connect but then the server sends me the information that he couldn´t received the host name server error message 400 ::request without hostname :: can you tell me why ?? the host name is in my example www.google.com // am i right ? ______________________________________________________________ thanks for reading through and im sorry for my bad english nXo

Share this post


Link to post
Share on other sites
quote:
Original post by NexusOrganicus
sprintf (command, "GET %s HTTP/1.0\nHost: %s\n\n",file,host);
\n will give you ASCII 10 (LF), I believe. You need ASCII 13+10 (CRLF).

Share this post


Link to post
Share on other sites
to solve that ....? am iright please correct me
i know that i may be an idiot ..

is it possible to solve the problem that way

char CRLF=23;

sprintf(command,"GET %s HTTP/1.1%c%cHost: http://%s%c.....blabla
???????
not really ? or
nxo

Share this post


Link to post
Share on other sites
Nothings working at all
i am not receiving any message from the server ....

/////////////////////////////////////////////////////////
sprintf(command,"HEAD %s HTTP/1.1\r\n"
"Host: http://%s\r\n",file,ipadr);
send(sockfd,command,strlen (command),0)
while((recv(sockfd,buffer,strlen (buffer), 0))>0)
{
printf("%s",buffer);
}
////////////////////////////////////////////////////////

i don´t know why it isn´t working..........
\r\n does nothing i don´t get any data sent from the server
what should i do ?
is the problem the http protokol or is it me ?
maybe you have other suggestions
thx
nxo

Share this post


Link to post
Share on other sites
quote:

sprintf(command,"HEAD %s HTTP/1.1\r\n"
"Host: http://%s\r\n",file,ipadr);


You need to end the header with a double CRLF.

sprintf(command,"HEAD %s HTTP/1.1\r\n"
"Host: http://%s\r\n\r\n",file,ipadr);

With a single CRLF, the server is just sitting there and waiting for you to either send another CRLF or send more options in the header. It won''t send anything to you before you have sent a double CRLF.

Share this post


Link to post
Share on other sites
Ok it works but only on www.google.com
on other sides i geth this message ___



148



Bad Request


Your browser sent a request that this server could not understand.


Invalid URI in request GET *.html HTTP/1.1




Apache/1.3.26 ServHTTP/1.1 400 Bad Request

Date: Thu, 05 Jun 2003 13:22:51 GMT

Server: Apache/1.3.26 (Unix) PHP/4.0.6

Connection: close

Transfer-Encoding: chunked

Content-Type: text/html; charset=iso-8859-1

Share this post


Link to post
Share on other sites
if i use this kinda code

sprintf(command,"GET %s HTTP/1.1\n"
"Host: %s\r\n",file,ipadr);
nothing happens and i get no reply

if i use this kinda code
_____________________________
sprintf(command,"GET %s HTTP/1.1\n"
"Host: %s\n\n",file,ipadr);
i get an error message that i sent him a wrong URI
_:__________________________________________________

Please understand i am new to this and i have no idea of
http request messages..........
lol
sorry ya
NxO

Share this post


Link to post
Share on other sites
quote:
Original post by NexusOrganicus
Invalid URI in request GET *.html HTTP/1.1
Of course, that is an invalid URI. What is it you try to request? Do read the HTTP/1.1 specification. The most simple request line is "GET / HTTP/1.1", and you will in almost all cases want to have the URI start with a slash, for example "GET /path/to/resource HTTP/1.1".

Share this post


Link to post
Share on other sites
sorry i am an idiot .... lol
____________________________
well what i wannt is to receiv the start page !!
only in text that´s all what i want ??
so i tried to get a *.html ?
i think thats wrong _ am i right ?
____________________________________
but how can i do that or do you know some
internet resources where i can take a look at ,
some tutorials about http request protocols ?
thanks alot you are all agreat help for me
_____thanks gurus _____

nxo

Share this post


Link to post
Share on other sites
You can't use "*.html" which doesn't really make sense, you can't request an array of files.

Try this:

host="www.gamedev.net"
file="/community/forums/topic.asp?topic_id=161102"

~CGameProgrammer( );



[edited by - CGameProgrammer on June 5, 2003 11:02:34 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by CWizard
Of course, that is an invalid URI. What is it you try to request?

It looks like he''s trying to aim OS file system commands at a web-server. Looks sus'' to me...

Share this post


Link to post
Share on other sites
quote:
Original post by NexusOrganicus
well what i wannt is to receiv the start page !!
only in text that´s all what i want ??
so i tried to get a *.html ?
i think thats wrong _ am i right ?
You are right, it is wrong. To get the start page, request "GET / HTTP/1.1". Telnet to an HTTP server (port 80) and experiment for yourself.
quote:
do you know some internet resources where i can take a look at , some tutorials about http request protocols ?

Well, there's always: RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1

[edited by - CWizard on June 5, 2003 11:25:25 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by NexusOrganicus
ok i´ll try-
another question
how can i receive information about the files on the server
for example to look if there is a index.html or something like that ?
Eh, you cannot retrieve any formal file listings, if that is what you mean. You can however retrieve a server generated file listing if you request a directory which doesn''t have an index document (eg. index.html) and the server is configured to allow that.

You can get "information" about a resource, without retrieving it by using HEAD instead of GET. That will give you back the exact headers but not the entity body. The only way to see if a file exist, is to try to request it with either GET or HEAD.

"Index files", such as index.html, are automatically used by the server, not the client. When you visit GameDev, your browser does not try to find the true "index document"; that is the servers job.

Share this post


Link to post
Share on other sites
Ok that is hardly to much info for me
i am sitting in front of the computer for hardly 12 hours ---
lol
_---- i have to take a break -.

i finally finished what i wantet to do -

to view the source code -.---
go to www.konsum.net\halbformat\

i thank all of you
tomorow is another day
sorry for my bad english----
____________________________

I thank all of you especially c-wizard for his support

thanks guys -- have a look at my output and my source if you want to // on www.konsum.net/halbformat

NxO
______________

Share this post


Link to post
Share on other sites
Use "HTTP/1.0". You seemed to have switched to HTTP/1.1

You don''t want to. Trust me. Anyway, you don''t even need to send valid headers (jsut the request) with most dedicated webservers.

Google responds to just a

"GET / HTTP/1.0\r\n\r\n"

just fine. something on a virtual server provider (gdnet?) requies the hostname you expect to reach, since it servers multiple hosts at the same IP address.

Share this post


Link to post
Share on other sites
quote:
Original post by C-Junkie
Use "HTTP/1.0". You seemed to have switched to HTTP/1.1

You don''t want to. Trust me. Anyway, you don''t even need to send valid headers (jsut the request) with most dedicated webservers.

Google responds to just a

"GET / HTTP/1.0\r\n\r\n"

just fine. something on a virtual server provider (gdnet?) requies the hostname you expect to reach, since it servers multiple hosts at the same IP address.
The ''Host:'' header is required in HTTP/1.1, and it doesn''t exist (as a standard header) in HTTP/1.0.

If you want to take advantage of HTTP/1.1 you must always send a ''Host:'' header, regardless if the target web server hosts multiple hosts or not. And, you can never assume that the web server is ''dedicated'', so you should always send the host name with the request, unless you''re just testing on a known server.

Share this post


Link to post
Share on other sites