1

I am currently developing a web application with angular2. I followed the Tour of Heroes tutorial to get the basics. So, my local server setup and application architecture is the same one.

I now need to perform a POST request to a static file. I managed to get the request sent, but the server answers 404 not found. Inspecting the network requests with Firebug, i can see this:

enter image description here

This is really weird, since the file exists and the url is correct. In fact, if I paste it in a browser (and perform a GET request), i can retrieve the json correctly.

I think that this could be caused by bad server end configuration. As the angular2 tutorial, i am using lite-server, but something is wrong.

Any clue?

frogatto
  • 28,539
  • 11
  • 83
  • 129
  • 4
    What do you mean by "POST request to a static file". What do you expect to happen by this request. A `POST` request is usually to be processed by the server. A `GET` request can usually just load some existing file if it's served by the server under the requested path. – Günter Zöchbauer Mar 25 '16 at 15:58
  • 3
    What don't you use a `GET` request from your code as well if this is working? – Günter Zöchbauer Mar 25 '16 at 16:04
  • Hi Gunter. The request needs to be a POST, because in the future it will be processed by the server as you said. I am just using the json file to simulate the server response. – Davide Abati Mar 29 '16 at 06:24
  • I guess you need special server support for `POST` requests to static files. Haven't tried this myself yet and I don't know lite-server. – Günter Zöchbauer Mar 29 '16 at 06:25

1 Answers1

0

I don't what you want exactly do, must it seems that there is a little incomprehension somewhere.

I you do a HTTP POST request, is it because you want to modify a resource present on the server ? If this the case, you would need to host a script on your server and not a simple static file. I you do not want to update the resource, but only want to query it, then you can access to your static file by making a HTTP GET request.

this.http
  .get('static/cambio-icona.json')
  .map(res => res.json())
  .subscribe(icona => this.icona = icona);
gentiane
  • 6,715
  • 3
  • 23
  • 34
  • The point is the following. I need to develop a API that listens to both GET and POST requests from the client. Anyway, i am still developing the front end and, as i use to do, i simulate such server responses with mock json files. For company related purposes, I need to get the front end working before starting to develop the back end. I used this mock-json strategy many times in the past (mostly with Backbone.js) – Davide Abati Mar 29 '16 at 06:18
  • And yes, this call needs to modify a resource on the server. "cambio-icona" stands for "change-icon". – Davide Abati Mar 29 '16 at 06:27