我正在尝试使用其他端口从另一个微服务(本地)检索json。我不确定问题出在我的配置还是微服务上。当我点击url时,确实将json显示在页面上。
this.http.get('http://localhost:8081/*****', { responseType: 'json' }).subscribe(data => console.log(data));
*****
=检索json的页面
我期待一个json,但是我收到一条错误消息。
答案 0 :(得分:1)
您应该具有以下内容:
//store first one as zero point
if (pos.id == 0)
{
pos.position = Eigen::Vector3d(0, 0, 0);
}
//store second as X axis
if (pos.id == 1)
{
pos.position = Eigen::Vector3d(<Distance from 1 to 2>, 0, 0);
}
//triangulate third from distances
if (pos.id == 2)
{
double c = //distance from 3 to 1
double b = //distance from 3 to 2
double a = //distance from 1 to 2
pos.position.x() = (c*c - b * b + a * a) / (2 * a);
pos.position.y() = std::sqrt(c*c - pos.position.x()*pos.position.x());
}
来自您的组件:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
@Injectable()
export class TestService {
constructor(private httpClient: HttpClient) { }
public getData(): Observable<any> {
const apiURL = `http://localhost:8081/*****`;
const opts = {
responseType: 'json'
};
return this.httpClient.post(apiURL, opts);
}
}
答案 1 :(得分:0)
对于遇到相同问题的任何人,我都发现了我的错误。另一个微服务上的控制器在RequestMapping之前缺少@CrossOrigin。这将我的错误修复在进行呼叫的前端。
@CrossOrigin
@RequestMapping("/{id}")
public Account retrieve(@PathVariable Long id) {
// ...
}