📄 basic_authentication.c
字号:
// Basic Authentication demo.
// The Web server serves a page only after receiving the user name and password
// defined for the realm.
// This file and other embedded Ethernet and Internet code and resources are
// available from www.Lvr.com.
// Select a network configuration from \lib\tcpip\tcp_config.lib
// in the Dynamic C distribution.
#define TCPCONFIG 1
// All C functions not declared as root go to extended memory.
#memmap xmem
// The dcrtcp library supports IP and TCP; the http library supports HTTP functions.
#use "dcrtcp.lib"
#use "http.lib"
// ximport loads a file from the development PC into the Rabbit's flash memory.
// The symbol (index_html) is a macro that gives the file's length and
// physical address in the Rabbit's memory.
// YOU MUST CHANGE THE PATH to match the location of the file in your system.
// OK to use forward or back slashes as separators.
#ximport "c:\my documents\ethernetexamplesrelease\rabbit\BasicAuthentication\index.html" index_html
// The HttpRealm structure contains the user name ("embedded") and password
// ("ethernet") to access resources in a realm ("Lakeview Research").
const HttpRealm myrealm[] =
{
{"embedded", "ethernet", "Lakeview Research"}
};
// The HttpType structure names the handler to use with specific file extensions.
// The first item in the structure is the handler used when a request
// doesn't name a page or other resource.
// This structure specifies using the default handler for HTML pages.
// The default handler serves the resource unchanged.
const HttpType http_types[] = {
{ ".html", "text/html", NULL}
};
// The HttpSpec structure contains information about the files, variables,
// and structures the Web server can access.
// On receiving a request for the file index.html or a request with no file
// name specified, the Web server requests the user name and password defined
// for the realm myrealm. On receiving the correct values, the server serves
// the page.
const HttpSpec http_flashspec[] = {
{ HTTPSPEC_FILE, "/", index_html, NULL, 0, NULL, myrealm},
{ HTTPSPEC_FILE, "/index.html", index_html, NULL, 0, NULL, myrealm}
};
main() {
// Initialize the TCP/IP stack and the web server.
sock_init();
http_init();
// For improved performance, reserve port 80 for the Web server.
tcp_reserveport(80);
while (1) {
//The main program loop calls http_handler repeatedly to process HTTP
// requests.
http_handler();
// Code to perform other tasks can be placed here.
}
} // end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -