By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,483 Members | 1,614 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,483 IT Pros & Developers. It's quick & easy.

network program

P: n/a
hello everyone,

i have a problem regarding networking apis of unix link systems ....i
don know this is the best place this
request but i cudnt get one .(so also suggest where to ask such
questions)

the problem is that after finally connecting to the server when i send
a get request the server returns bad request error ...i use something
like:

write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */
/
*by the sizeof operator of c (here i wrote 50*/

where is the problem in the system (server ,code ,write() ,etc)
the server is apache running on my local machine ....

how are \r\n interpreted by write() .....
i use fedora8(linux)

thanks a lot
Mohan
Nov 8 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
mohi said:
hello everyone,

i have a problem regarding networking apis of unix link systems ....i
don know this is the best place this
request but i cudnt get one .(so also suggest where to ask such
questions)
comp.unix.programmer is probably your next port of call.
the problem is that after finally connecting to the server when i send
a get request the server returns bad request error ...i use something
like:

write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */
You might want to make that 44 (no null terminator) or 45 (to include the
terminator). You're trying to write more data than you have legal access
to.

For the protocol stuff, I really do recommend that you talk to
comp.unix.programmer in the first instance.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 8 '08 #2

P: n/a
>i have a problem regarding networking apis of unix link systems ....i
>don know this is the best place this
request but i cudnt get one .(so also suggest where to ask such
questions)
comp.unix.programmer would be a better place to ask.
>the problem is that after finally connecting to the server when i send
a get request the server returns bad request error ...i use something
like:

write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */
The interpretation of \r and \n in the string literal above is
not done by write(), it's done by C for the string literal.

Manually telnet to your server on port 80 and type in the request.
I get a response before I can even start typing the " Host:" header.
I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.

My Apache will accept, and ignore, a " Host:" header, as distinguished
from a "Host:" header. However, a "Host:" header is mandatory on
a HTTP/1.1 request. Unless you include a "Host:" header, with or
without a " Host:" header, the request will fail. A " Host:" header
is just a waste of bandwidth.
Nov 8 '08 #3

P: n/a
In article <Uv******************************@posted.interneta merica>,
Gordon Burditt <go***********@burditt.orgwrote:
>>write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */

The interpretation of \r and \n in the string literal above is
not done by write(), it's done by C for the string literal.

Manually telnet to your server on port 80 and type in the request.
I get a response before I can even start typing the " Host:" header.
I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.
A GET without a version number is a "Simple-Request" which is for
compatibility with HTTP 0.9. See RFC 1945.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 8 '08 #4

P: n/a
On Nov 9, 3:39 am, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
In article <UvmdnQsFtbePmovUnZ2dnUVZ_jidn...@posted.interneta merica>,

Gordon Burditt <gordonb.of...@burditt.orgwrote:
>write(sockfd,"GET /index.html \r\n Host: 10.10.19.222:80\r\n\r\n",
50); /*the size argument actually is given */
The interpretation of \r and \n in the string literal above is
not done by write(), it's done by C for the string literal.
Manually telnet to your server on port 80 and type in the request.
I get a response before I can even start typing the " Host:" header.
I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.

A GET without a version number is a "Simple-Request" which is for
compatibility with HTTP 0.9. See RFC 1945.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
ok i was having an extra space before the header Host:.....but now
theres another problem

i just tried to GET the image -i show u inputs that are taken by my
program

enter the server ip address : 10.10.19.222

enter the port at which to connect to the server : 9029
sucessfully connected to the server
enter the url to request(without spaces) :http://10.10.19.222:9029/
home/Mohan/mine/web/images/tech.jpg

reading frm the server......
now after this the output from the server is saved in a file which has
contents like

HTTP/1.1 200 OK^M
Date: Sun, 09 Nov 2008 06:36:32 GMT^M
Server: Apache/2.2.6 (Fedora)^M
Last-Modified: Fri, 07 Nov 2008 12:27:31 GMT^M
ETag: "1780314-1533e9-897f32c0"^M
Accept-Ranges: bytes^M
Content-Length: 1389545^M
Connection: close^M
Content-Type: image/jpeg^M
X-Pad: avoid browser bug^M
^M
<90>
ExifRL failed: 6
2009-09-26 22:31:06, Fetching URL failed: 6
h1>Moved Permanently</h1>
<p>The document has moved <a href="http://10.10.19.222:9029/home/
Mohan/">here</a>.</p>
<hr>
<address>Apache/2.2.6 (Fedora) Server at 10.10.19.222 Port 9029</
address>
</body></html>
~

but when i try to view this from the browser with exactly the same url
i have the image .....what can be wrong....

thanks a lot
Nov 9 '08 #5

P: n/a
On 9 Nov 2008 at 6:48, mohi wrote:
2009-09-26 22:31:06, Fetching URL failed: 6
h1>Moved Permanently</h1>
<p>The document has moved <a href="http://10.10.19.222:9029/home/
Mohan/">here</a>.</p>

but when i try to view this from the browser with exactly the same url
i have the image .....what can be wrong....
The server will have sent back a 301 status code to indicate that the
document has been permanently moved, and its new location will be
supplied in the Location header. Your browser is set up to automatically
follow this redirect, but you aren't doing so.

Nov 9 '08 #6

P: n/a
mohi wrote, On 09/11/08 06:48:
On Nov 9, 3:39 am, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
>In article <UvmdnQsFtbePmovUnZ2dnUVZ_jidn...@posted.interneta merica>,

Gordon Burditt <gordonb.of...@burditt.orgwrote:
<snip>>
>>I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.
A GET without a version number is a "Simple-Request" which is for
compatibility with HTTP 0.9. See RFC 1945.

ok i was having an extra space before the header Host:.....but now
theres another problem

i just tried to GET the image -i show u inputs that are taken by my
program
<snip>

This is not the right pace to discuss the HTTP protocol. HTTP does not
even have the letter C in it! There are plenty of other groups, mailing
lists and forums, please find one where HTTP is topical if you want to
discus it.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 9 '08 #7

P: n/a
On Nov 9, 4:25 pm, Flash Gordon <s...@spam.causeway.comwrote:
mohi wrote, On 09/11/08 06:48:
On Nov 9, 3:39 am, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
In article <UvmdnQsFtbePmovUnZ2dnUVZ_jidn...@posted.interneta merica>,
Gordon Burditt <gordonb.of...@burditt.orgwrote:

<snip>>
>I think you need to make a HTTP 1.1 request, not a HTTP 1.0 request.
See RFC2616.
A GET without a version number is a "Simple-Request" which is for
compatibility with HTTP 0.9. See RFC 1945.
ok i was having an extra space before the header Host:.....but now
theres another problem
i just tried to GET the image -i show u inputs that are taken by my
program

<snip>

This is not the right pace to discuss the HTTP protocol. HTTP does not
even have the letter C in it! There are plenty of other groups, mailing
lists and forums, please find one where HTTP is topical if you want to
discus it.
--
Flash Gordon
If spamming me sent it to s...@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me athttp://clc-wiki.net/
sorry guys for this ...
but iam not getting a place to discuss allthis
can anyone suggest any lik where i can discuss http protocol

thanks a lot
Nov 9 '08 #8

P: n/a
>i just tried to GET the image -i show u inputs that are taken by my
>program
u died after taking a job at the United Nations, so his advice won't
be much help..
reading frm the server......
You don't show the code that reads from the server or the code that
logs to the log file.
>now after this the output from the server is saved in a file which has
contents like
This looks like a mismash of several requests. A "moved permanently"
response should not be returning code 200. Does the message "ExifRL
failed: 6" appear in YOUR program or a library your program uses?

THIS PART REALLY IS RELEVANT TO COMP.LANG.C:
If you fread() (or use the POSIX function read()) data from the
server, then write it to a file with something like

fprintf(logfile, "%s", buffer);
you have a problem. fread() and read() do not guarantee that the
data read is terminated by a '\0' terminator, so you may end up
with extra crap written also - and it looks like you did. Use
fwrite, using the length of the data actually read, or place a
terminator before attempting to fprintf() it.

Also, you can't count on the entire response being fetched in one
fread() or read(), especially since the content sent seems to be a
bit shy of 1.4 megabytes.

>HTTP/1.1 200 OK^M
Date: Sun, 09 Nov 2008 06:36:32 GMT^M
Server: Apache/2.2.6 (Fedora)^M
Last-Modified: Fri, 07 Nov 2008 12:27:31 GMT^M
ETag: "1780314-1533e9-897f32c0"^M
Accept-Ranges: bytes^M
Content-Length: 1389545^M
Connection: close^M
Content-Type: image/jpeg^M
X-Pad: avoid browser bug^M
^M
<90>
The above bytes look like the first few bytes of an actual jpeg image.
The headers suggest that the content was a little under 1.4 megabytes
long.
>ExifRL failed: 6
2009-09-26 22:31:06, Fetching URL failed: 6
h1>Moved Permanently</h1>
<p>The document has moved <a href="http://10.10.19.222:9029/home/
Mohan/">here</a>.</p>
<hr>
<address>Apache/2.2.6 (Fedora) Server at 10.10.19.222 Port 9029</
address>
</body></html>
Nov 9 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.