I have an Angular2 App running that is attempting to make a call to my Django server.
I have a function called getObjects That makes the external API call and should return a list of objects. As a bit of debugging I am currently making a XMLHttpRequest, which correctly grabs the data from my server.
However, whenever I attempt to make a request using Http.http.get(url) I see a 404 error. I've tried fiddling with a few of the HTTP headers, as well as playing around with some settings on my server, but I cannot figure out what is wrong.
I assume that the Http.http.get() method is doing something funky behind the scenes that I am unaware of. The odd thing is that my browser dev-network tab doesn't even show any attempt to reach my external browser.
Any help in the matter would be much appreciated, I can provide any additional debug information and could really use a point in the right direction.
ng --version
angular-cli: 1.0.0-beta.24
node: 6.9.1
os: win32 x64
@angular/common: 2.4.3
@angular/compiler: 2.4.3
@angular/core: 2.4.3
@angular/forms: 2.4.3
@angular/http: 2.4.3
@angular/platform-browser: 2.4.3
@angular/platform-browser-dynamic: 2.4.3
@angular/router: 3.4.3
@angular/compiler-cli: 2.4.3
import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
...
constructor(private http: Http) { }
getObjects(): Promise<Object[]> {
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
var x = httpGet(this.myUrl);
console.log(x); // This works perfectly and I see an entry on my server log
this.http.get(this.myUrl)
.subscribe(res => console.log(res));// This throws a 404 and I see no entry on my server logs nor in my browser network tab
var headers = new Headers({'content-type': 'application/json'});
this.http.get(this.myUrl, {headers: headers})
.subscribe(res => console.log(res));// This throws a 404 and I see no entry on my server logs nor in my browser network tab
return this.http.get(this.myUrl)
.toPromise()
.then(response => response.json().data as Object[])
.catch(this.handleError); //The original code that worked on an internal in-memory-api
}