使用定义路径的不同处理程序执行此操作,例如:
[_webServer addHandlerForMethod:@"GET"
path:@"/path/one"
requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
GCDWebServerDataResponse* response = [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello World</p></body></html>"];
return response;
}];
第二个可能看起来像这样:
[_webServer addHandlerForMethod:@"GET"
path:@"/path/two"
requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
GCDWebServerDataResponse* response = [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello a second time</p></body></html>"];
return response;
}];
示例位于:https ://github.com/swisspol/GCDWebServer