TreeFrog (C + + Web Framework) 가 개발 한 http 파일 서버
2440 단어 framework
/controller-name/action-name/argument1/argument2/...
우리 의 fileserver 프로젝트 에 대응 하여 controller - name 은 fileserver 이 고 action - name 은 files 이 며 argument 1 은 구체 적 인 파일 이름 입 니 다.파일 에 접근 할 때 다음 주 소 를 사용 합 니 다:http://localhost:8800/fileserver/files/xxx 。
Google 은 이전 Hello World 예제 를 간단하게 개조 하면 http 파일 서버 를 얻 을 수 있 습 니 다.
헤더 파일 은 다음 과 같 습 니 다:
#ifndef FILESERVERCONTROLLER_H
#define FILESERVERCONTROLLER_H
#include "applicationcontroller.h"
class T_CONTROLLER_EXPORT FileServerController : public ApplicationController
{
Q_OBJECT
public:
FileServerController(){}
FileServerController(const FileServerController &other);
public slots:
void index();
void files();
void files(const QString ¶m);
};
T_DECLARE_CONTROLLER(FileServerController, fileservercontroller);
#endif // FILESERVERCONTROLLER_H
상기 코드 에서 Public slots: 아래 부분 은 action 입 니 다.tfserver 가 URL 을 분석 하면 이 action 으로 호출 됩 니 다.우 리 는 files 라 는 slot 두 개 를 추가 했다.
다음은 원본 파일:
#include "fileservercontroller.h"
FileServerController::FileServerController(const FileServerController &other)
: ApplicationController()
{}
void FileServerController::index()
{
renderText("Denied");
}
void FileServerController::files()
{
renderText("Invalid parameter");
}
void FileServerController::files(const QString ¶m)
{
sendFile(param, "application/octet-stream", "");
}
T_REGISTER_CONTROLLER(fileservercontroller);
우 리 는 files 의 실현 에서 단지 sendfile 을 호출 하여 파일 을 보 낼 뿐이다.사실 sendfile 을 추적 하면 이 함 수 는 파일 을 찾 아 열 고 QIODevice 대상 지침 을 THttp Response 의 body Device 구성원 에 게 할당 하 는 것 일 뿐 입 니 다.추 후 에는 TActionThread 에서 이 body Device 로 실제 데이터 전송 동작 을 합 니 다.파일 을 열 때 파 람 은 파일 이름 으로 사이트 루트 디 렉 터 리 에서 찾 습 니 다 (예제 에 서 는 프로젝트 루트 디 렉 터 리).
이제 우 리 는 통과 할 수 있다.http://localhost:8800/fileserver/files/appbase.pri 이 URL 로 다운 로드 를 테스트 해 보 세 요.나 는 이곳 에서 정상적으로 일한다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Fragmenta의 각서라고 할까, 그것 밖에 발견되지 않았기 때문에 시도해보기로 했습니다. 다만, 내용을 보면 어플리케이션을 만드는 프레임워크로서 사용되는 것도 의식하고 있는 것 같습니다. 하지만, 지금은 정확하지 않은 것 같기 때문에,...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.