我使用SimpleJson plugin进行连接。 但是我收到错误502(PHOTO)
我在启动文件中添加了CORS:
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
然后按照GitHub docs文档中的说明为GET(/)和POSTS(/ query,/ annotations,/ search)创建端点:
using System.Net.Http;
using System.Text;
using Microsoft.AspNetCore.Mvc;
namespace Grafana
{
[ApiController]
public class BugsMonitoringController : ControllerBase
{
[HttpGet]
[Route("/")]
public void Empty()
{
}
[HttpPost]
[Route("query")]
public HttpResponseMessage Query()
{
return new HttpResponseMessage()
{
Content = new StringContent("[{\"columns\":[{\"text\":\"Time\",\"type\":\"time\"},{\"text\":\"Country\",\"type\":\"string\"},{\"text\":\"Number\",\"type\":\"number\"}],\"rows\":[[1234567,\"SE\",182],[1234567,\"DE\",282],[1234567,\"US\",382]],\"type\":\"table\"}]", Encoding.UTF8, "application/json")
};
}
[HttpPost]
[Route("search")]
public HttpResponseMessage Search()
{
return new HttpResponseMessage()
{
Content = new StringContent("[ { \"text\" :\"upper_25\", \"value\": 1}, { \"text\" :\"upper_75\", \"value\": 2} ]", Encoding.UTF8, "application/json")
};
}
[HttpPost]
[Route("annotations")]
public HttpResponseMessage Annotation()
{
return new HttpResponseMessage()
{
Content = new StringContent("[{\"text\":\"text shown in body\",\"title\":\"Annotation Title\",\"isRegion\":true,\"time\":\"timestamp\",\"timeEnd\":\"timestamp\",\"tags\":[\"tag1\"]}]", Encoding.UTF8, "application/json")
};
}
}
数据源(PHOTO)中指示的服务器地址
答案 0 :(得分:0)
我解决了这个问题 当我在JSON插件中编写URL时,我使用了localhost:5000。需要使用您的本地地址,例如:192.168.1.10。并在launchSettings.json中更改“ applicationUrl”