ionic 2:http get 请求不工作(添加代理)
ionic 2: http get request not working (proxy added)
我正在使用来自@angular/http 的 Http 发送 GET 请求,但服务器没有收到请求。生成的 url 是正确的,因为当我记录它们并在浏览器中打开它们时(我已经尝试了所有 Chrome、Firefox 和 Safari),服务器确实收到了这些请求。
我就是这样做的:
let logButtonUrl = this.urlGenerator.generateTiramisuUrlTemp(this.servletPath,
argMap);
console.log("logButtonUrl:"+logButtonUrl);
return this.http.get(logButtonUrl).map(this.writeSuccess);
函数写入成功:
private writeSuccess(res: Response) {
let body = res.json();
let rows_affected = body.data[0].rowsAffected;
if (rows_affected == "1") {
return true;
} else {
return false;
}
}
我在浏览器控制台中没有收到错误消息,所以这可能不是因为这里讨论的 CORS 问题:
http://blog.ionic.io/handling-cors-issues-in-ionic/
我也试过使用代理。我在 ionic.config.json:
中添加了这个
{
"path": "/backendTemp",
proxyUrl": "http://128.237.217.70:8080" /*the ip address of the target server*/
}
并将我生成的网址中的 IP 地址替换为“/backendTemp”。还是不行。
关于这个的 suggestions/thoughts 吗?非常感谢!
使用 $http (https://docs.angularjs.org/api/ng/service/$http):
.controller('RequestCtrl', function ($http) {
$http({
method: 'GET',
url: 'http://128.237.217.70:8080/backendTemp'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
我正在使用来自@angular/http 的 Http 发送 GET 请求,但服务器没有收到请求。生成的 url 是正确的,因为当我记录它们并在浏览器中打开它们时(我已经尝试了所有 Chrome、Firefox 和 Safari),服务器确实收到了这些请求。
我就是这样做的:
let logButtonUrl = this.urlGenerator.generateTiramisuUrlTemp(this.servletPath,
argMap);
console.log("logButtonUrl:"+logButtonUrl);
return this.http.get(logButtonUrl).map(this.writeSuccess);
函数写入成功:
private writeSuccess(res: Response) {
let body = res.json();
let rows_affected = body.data[0].rowsAffected;
if (rows_affected == "1") {
return true;
} else {
return false;
}
}
我在浏览器控制台中没有收到错误消息,所以这可能不是因为这里讨论的 CORS 问题: http://blog.ionic.io/handling-cors-issues-in-ionic/
我也试过使用代理。我在 ionic.config.json:
中添加了这个{
"path": "/backendTemp",
proxyUrl": "http://128.237.217.70:8080" /*the ip address of the target server*/
}
并将我生成的网址中的 IP 地址替换为“/backendTemp”。还是不行。
关于这个的 suggestions/thoughts 吗?非常感谢!
使用 $http (https://docs.angularjs.org/api/ng/service/$http):
.controller('RequestCtrl', function ($http) {
$http({
method: 'GET',
url: 'http://128.237.217.70:8080/backendTemp'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});