1、创建项目
2、代码
procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var mPath, mXY, str : string;
jobj: TJSONObject;
begin
Response.ContentType:= 'application/json; charset="UTF-8"';
mPath:= Request.PathInfo;
mXY := Request.QueryFields.Values['XY']; //get请求获取Url后面的参数
jobj:= TJSONObject.ParseJSONValue(Request.Content) as TJSONObject; //获取body raw 里面的Json字符串
str := jobj.GetValue('Hint').Value;
if Request.Method='GET' then
begin
Response.Content := '{"code":200,"msg":"只支持Post请求"}';
Exit;
end;
if mPath = '/' then
begin
Response.Content := TJSONObject.Create.AddPair('code','200').AddPair('msg','服务运行中').ToString;
end
else
begin
Response.Content := TJSONObject.Create.AddPair('code','404').AddPair('msg','未定义请求路径').ToString;
end;
end;