1、这是简单HTTP实现示例的一部分。
#include ……
// HttpDaemon is the the class that implements the simple HTTP server.
class HttpDaemon : public QServerSocket
{
Q_OBJECT
public:
HttpDaemon( QObject* parent=0 ) :
QServerSocket(8080,1,parent)
{……}
void newConnection( int socket )
{……}
private slots:
void readClient()
{QSocket* socket = (QSocket*)sender();
if ( socket->canReadLine() ) {
QStringList tokens = QStringList::split( QRegExp("[ \n\r][ \n\r]*"), socket->readLine() );
if ( tokens[0] == "GET" ) {
QTextStream os( socket );
os.setEncoding( QTextStream::UnicodeUTF8 );
os << "HTTP/1.0 200 Ok\r\n"
"Content-Type: text/html; charset=\"utf-8\"\r\n"
"\r\n"
"<html>\n"
"<head>\n"
"<title>QObject::tr(大连理工大学)</title>\n"//想使用中文标题出现乱码
"<h1>Hello zhaoxiao 你好</h1>\n"
"</head></html>";//正文中想显示中文,结果打开网页是空。
socket->close();
emit wroteToClient();
}}}};
2、如果想做一简单的嵌入式web服务器
在PC机浏览器上可以浏览到嵌入式设备里面的信息。
我觉得自己对于如何解决大致的思路都没有搞清楚。
呵呵麻烦给点意见或者这方面的范例和资料。
期待你的回复!
[ 此贴被XChinux在2006-04-20 15:51重新编辑 ]