Re: Little problem with C program



Elekaj wrote:

> This is my problem, the function listed under this text does'nt seems to
> work correctly.

Dude, I was just looking for C-style code to ping one web page or return an
error. Thanks!

> printf("Sending request : %s\n",request);
> send(cddbSocket,&request,sizeof(request),0);

You need to learn more C before coding hard things in it. For example,
'sizeof request' returns the size of a pointer, not the length of the
pointed-to string. Use strlen().

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

And request has no &.

(Then consider using a softer language, like Ruby, which comes with
libraries that handle raw HTTP, so you can skip ahead to actually doing what
you need to do with HTTP.)

I used this tutorial to get your snip working:

http://www.codeproject.com/internet/winsockintro02.asp

> When I call the function requestHTTP("80","192.168.0.1","GET\n"), the
> function works fine until the read command (on the screen, there are the
> message "Reading response ..." and nothing else appens.

You need to use recv(), to await and receive bytes. I think "read()" is for
other situations where you already have the bytes and just need to pull them
out of the socket's internal buffer.

So I added WSAStartup(), and got stuff working with this loop:

printf("Sending request : %s\n",request);

sprintf(response,"GET %s\r\n\r\n",request);
send(cddbSocket,response,strlen(response),0);

printf("Reading response ...\n");

int y;

while(y=recv(cddbSocket,response, sizeof response,0))
{
puts (response);
}

That system puts the GET inside the function, so I call it like this:

requestHTTP("8888", "localhost", "/FrontPage")

Note the /. HTTP will kack for no reason without it.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


.



Relevant Pages

  • Re: Screen Scraping a Password Protected Site
    ... http traffic. ... cookies to a singleton CookieContainer and the once you have logged in ... If TypeOf request Is HttpWebRequest Then ... If TypeOf response Is HttpWebResponse Then ...
    (microsoft.public.dotnet.languages.vb)
  • Fwd: Hello
    ... response = meth ... raise HTTPError, code, msg, hdrs, fp) ... But now when I use this http request ...
    (comp.lang.python)
  • Re: Using HttpWebRequest and HttpWebResponse
    ... when an HTTP 4xx or 5xx status is returned. ... variable to WebException.Response - the original response. ... a request to http://someaddress/someresource. ...
    (microsoft.public.dotnet.framework)
  • Re: HTTP question
    ... > then before I receive any response back from the server I issue another GET ... > request for a different web page. ... Will I get an error back from the server? ... HTTP client waits for the first response before sending the second ...
    (comp.infosystems.www.servers.misc)
  • Re: W2K3 IIS 6.0 ASP.NET Requests Per Second Limits?
    ... allow the page to tell ASP.Net "don't send a response yet until I tell ... this request is "leaked" and will never ... It is when the callback executes with both the async function call ... The thread executing code literally calls into Function1, execute code, ...
    (microsoft.public.inetserver.iis)