How do I send html data back on ChannelHandlerContext ctx?

24 views
Skip to first unread message

goodnews...@gmail.com

unread,
Jul 15, 2019, 11:26:21 PM7/15/19
to Netty discussions
Hello,

I have a great video game server I've worked on for over a thousand hours.
I am coding up account recovery via email, and for security purposes, they need to click a url.
This recovers their account.

But when they click the url, I want their webbrowser to display,"Success, check your game on your phone. Your account is recovered."

It can recover it now, but I want the webbrowser not to display nothing.

I tried

ctx.write("Hello World");
ctx.flush();

I am thinking some rudimentary html headers are needed.

Any help is thanked. God bless all of yinz for reading.

www.crystalfighter.com/battlemon

,Jim

goodnews...@gmail.com

unread,
Jul 24, 2019, 5:18:02 AM7/24/19
to Netty discussions
My server gets:
GET /jibberish HTTP/1.1
Host: 127.0.0.1:80
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

I sent a packet full of nonsense, chrome says,"This page is not working."

I tried sending this packet "HTTP/1.1 200 OK\nDate: Wed, 24 Jul 2019 05:07:53 GMT\nServer: Custom (Win64)\nLast-Modified: Wed, 24 Jul 2019 04:16:26 GMT\nETag: \"4014300565a5-2c-3e94b66c2e410\"\nAccept-Ranges: bytes\nContent-Length: 44\nConnection: close\nContent-Type: text/html; charset=UTF-8\nX-Pad: avoid browser bug\n<html><body><h1>It works!</h1></body></html>"

Chrome just hangs... any further help?

Rogan Dawes

unread,
Jul 24, 2019, 11:07:24 AM7/24/19
to ne...@googlegroups.com
Http headers should be CRLF-terminated, and you need two CRLF between the last header and the start of the content.

Perhaps you should use the existing HTTP server codec, though, which takes care of these details for you?

Rogan


--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/75292ecc-2299-4281-8ead-a469d70dc01b%40googlegroups.com.

goodnews...@gmail.com

unread,
Jul 31, 2019, 4:23:57 PM7/31/19
to Netty discussions
Figured it out!

It is just a normal packet with an html header on it:
Like http 1.1 blah blah blah /r/n
Host blah blah /r/n
Etc

Then just an html page


Super easy. Google http headers

Reply all
Reply to author
Forward
0 new messages