简体   繁体   English

angularjs http.get Web服务调用不适用于特定的URL

[英]angularjs http.get web service call is not working for particular url

I am trying to get a json object from a specific url, it is not working for some reason. 我正在尝试从特定的网址获取json对象,由于某种原因,它无法正常工作。 However same code works fine with different url. 但是,相同的代码可以在不同的网址下正常工作。 In the code below if I use 'restcountries' url it works fine, and it doesnt't work for 'wingerweb***' 在下面的代码中,如果我使用“ restcountries” URL,它可以正常工作,而对于“ wingerweb ***”则不起作用

import {Injectable} from "angular2/core"
import {Http} from 'angular2/http';
import 'rxjs/Rx';
import {Observable} from 'rxjs/Rx';

@Injectable()
export class CountryService{
   //endpoint_url:String = "https://restcountries.eu/rest/v1/region/oceania";
     endpoint_url:String = "http://cors.io/?u=http://wingerweb.azurewebsites.net/WingerApp/rest/menuitems/1";
    constructor(http: Http){
        this.http = http;
    }
    getCountriesByRegion (region:String){
        return this.http.get(this.endpoint_url)
                        .map(res => res.json())
                        .do(data => console.log(data))
                        .catch(this.handleError);
    }

    private handleError (error: Response) {
    console.log('here');
    console.error(error);
    return Observable.throw(error.json().error || 'Server error');
  }
}

Could you try encoding URL before get? 您能否在获取之前尝试对URL进行编码?

For example, 例如,

endpoint_url:String = "http://cors.io/?u=" + 
   encodeURIComponent("http://wingerweb.azurewebsites.net/WingerApp/rest/menuitems/1");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM