2013-04-16 6 views
0

몽구스 서버에 html 페이지를 표시하려고합니다. 아래 코드를 사용하여 어떤 코드가 문제인지 알려주려고했습니다.몽구스 서버를 사용하여 html 페이지를 표시

#include <stdio.h> 
#include <string.h> 
#include "mongoose/mongoose.h" 

static int begin_request_handler(struct mg_connection *conn) { 
    const struct mg_request_info *request_info = mg_get_request_info(conn); 
    static const char *login_url = "/index.html"; 
    mg_printf(conn, "HTTP/1.1 200 OK\r\n" 
      "Content-Type: text/html\r\n" 
      "Location: %s\r\n\r\n", login_url); 
    return 1; 
} 

int main(void) { 
    struct mg_context *ctx; 
    struct mg_callbacks callbacks; 
    const char *options[] = { "listening_ports", "8080", NULL }; 
    memset(&callbacks, 0, sizeof(callbacks)); 
    callbacks.begin_request = begin_request_handler; 
    ctx = mg_start(&callbacks, NULL, options); 
    getchar(); 
    mg_stop(ctx); 
    return 0; 
} 

답변

0

수행하려는 작업은 무엇입니까? 옵션 []에서 "document_root"를 추가하십시오 (당신은 mongoose에 대한 옵션에서 항상 document_root가 필요합니다), index.html을 해당 디렉토리에 넣고 mg_start에서 콜백을 제거하십시오. 몽구스가 index.html을 자동으로 게재합니다.