[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: how to properly format data when using TCPSocket.send

Gennady Bystritsky

12/29/2006 10:27:00 PM

Rob Muhlestein wrote:
> Nathan Taylor wrote:
>> It would be greatly appreciated if someone would clue me in to what
>> I am doing wrong here. I am trying to send this data below to
>> httpd(Apache) however I am receiving a http response code of 400
>> (bad request). Apache is logging "request failed: error reading the
>> headers" in error_log, however if I replace the \r\n with \x0d\x0a
>> and send this through netcat to Apache I get the proper response
>> code I am looking for.
>>
>>
>> http_socket = TCPSocket.new("#{i}", 80); http_socket.send("PUT
>> /puttest.html HTTP/1.0\r\nHost: #{i}\r\nConnection:
>> close\r\nContent-type: text/html\r\nContent-Length:
>> 309\r\n<html><head>See Spot Run!</head><title>See Spot
>> Run!</title><body>See Spot Run!</body></html>\r\n\r\n", 0)
>
> Looks like you found your answer, but one tool for sockets
> programming, if you aren't already using it, is 'nc'. It can be used
> as a 'telnet' replacement but more relevant to your case, you can
> make it into a web (or any) server and see every byte your client is
> sending:
>
> nc -l -k 3001
>
> ...will start your 'server'. Then you set your client to connect to
> localhost 3001, you can use nc as a client to test that as well:
>
> echo hello | nc localhost 3001

Thanks for mentioning nc, did not know that such a utility exists.
However, it worth mentioning that it is only BSD/Linux thingy (by
default), on Solaris here's what it is ;-) :

User Commands nc(1)

$ man nc

NAME
nc - Client program for NEdit text editor

SYNOPSYS
nc [-read] [-create] [-line n | +n] [-do command] [-[no]ask]
[-svrname name] [file...]

DESCRIPTION
nc is the client interface to the NEdit text editor. To use
...


Gennady.


1 Answer

AdSR

12/30/2006 10:33:00 AM

0

Gennady Bystritsky wrote:
> [snip]
> Thanks for mentioning nc, did not know that such a utility exists.
> However, it worth mentioning that it is only BSD/Linux thingy (by
> default), on Solaris here's what it is ;-) :

http://netcat.source... might help.