The server is not allowing the requested method through HTTP POST and therefore returning

Excuse me if this question sounds beginner or if my terminology is incorrect, because I am new to this.

I have created a basic Python API for reading and writing to a database (CSV file) with Angular 5 as my front end. While I was able to successfully retrieve data from the server, I am encountering issues when trying to post to it. Here is where I think the problem lies:

The method of posting data involves sending an array of JSON objects.

The relevant code snippet is as follows: On the component.ts side:

this._svc.postAPI(this.csvData)
    .subscribe(
      res => console.log(res),
    error => alert('Error!'),
  ()=> 'Data Submitted to database') 
  }

On the services.ts side:

postAPI(data): Observable<any>{
    return this.http.post(this.urlAPI, data);
  }

The error message "405 Method Not Allowed" is displaying, and the Network tab in the console shows:

General

Request URL: http://192.168.0.2:5050/api
Request Method: OPTIONS
Status Code: 405 Method Not Allowed
Remote Address: 192.168.0.2:5050
Referrer Policy: no-referrer-when-downgrade

Response Headers

Allow: POST
Content-Length: 23
Content-Type: text/plain; charset=utf-8
Date: Thu, 12 Jul 2018 03:20:39 GMT
Server: Python/3.5 aiohttp/2.3.10

Request Headers

Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Access-Control-Request-Headers: content-type
Access-Control-Request-Method: POST
Connection: keep-alive
Host: 192.168.0.2:5050
Origin: http://evil.com/
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36

Postman works fine, so the URL appears correct; however, the issue seems to be related to the data being sent.

I have tried the following approaches:

This did NOT work:

postAPI(data): Observable<any>{
return this.http.post(this.urlAPI, '{}');
}

but this DID work:

postAPI(data): Observable<any>{
return this.http.post(this.urlAPI, '[{}]');
}

and this DID work:

postAPI(data): Observable<any>{
return this.http.post(this.urlAPI, '
[
    {
        "info": "A",
        "dev": "T",
        "but": "C",
        "msg": "X"
    }
]
');
    }

I believe the format of the data I'm attempting to post is also in the same JSON array format.

Any help would be greatly appreciated.

Answer №1

405 suggests an issue with your script. If one version is functioning properly, the problem is unlikely to be caused by the web server. Make sure to include the [] brackets for this particular type of error.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What might be preventing combineLatest from executing?

Currently, I am attempting to run a block of code utilizing the combineLatest function. Within my translation library, there exists an RXJS Observable that is returned. Imported as individual functions are combineLatest, map, and tap. combineLatest(this. ...

Access data from JSON array in Angular 2

I'm facing a basic issue here. I have a JSON file named pageDefinition.json that is being loaded into my component. Here's how the JSON data looks: ... "testArray": [ {"id": 0, "name": "row1"}, {"id": 1, "name": "row2"}, {"id": 2, "n ...

JavaScript 200 code doesn't execute the success function for the post method

Hey there! I'm having an issue with sending json to a django web service. Strangely, the success function isn't triggering even though I receive a 200 status code. I've tried changing the data type to "json", "text", and "html", but still no ...

Are you encountering issues with Google Analytics performance on your Aurelia TypeScript project?

I recently started using Google Analytics and I am looking to integrate it into a website that I'm currently building. Current scenario Initially, I added the Google Analytics tracking code to my index.ejs file. Here is how the code looks: <!DOC ...

Protractor end-to-end tests fail to run properly when the `--spec` flag is utilized

Currently, I am running 'ng e2e' on an Angular CLI project and I am looking to specify a specific test to run instead of running all of them. When I execute ' ng e2e --aot ', the test runs smoothly. However, when I try ' ng e2e ...

Assign an event listener to a collection of elements

Suppose I have an Array containing elements and another Array consisting of objects in the exact same index order. My goal is to add a click event for each element that will display a specific property of each object. For instance: myDivArray = [ div0, d ...

Trouble with Excel Office Script setInterval functionality

Trying to automatically recalculate an Excel worksheet every second using Office Script. Unfortunately, my initial approach did not succeed. function sendUpdate(sheet: ExcelScript.Worksheet) { console.log('hi'); sheet.calculate(true); } func ...

"Ionic Calendar 2 - The ultimate tool for organizing your

I am using a calendar in my Ionic app that retrieves events from a database through an API. var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://portalemme2.com.br/SaoJoseAPI/agenda', true); this.http.get('http://portalemme2.c ...

Experiencing the error message "delete(...).then(...).error is not a function" while attempting to remove a file from Firebase storage using AngularFire and TypeScript

I'm trying to implement the code snippet from Firebase documentation to delete a file and then upload a new image in the same directory on Firebase Storage. However, I keep encountering an error message saying "delete(...).then(...).error is not a fun ...

Strategies for effectively conveying jQuery and Angular

I have integrated jQuery DataTable into my code. I am facing an issue with the dataTables_scrollBody class which requires me to add a custom scroll bar. This is necessary because on Linux, the touch screen functionality in Chrome is not working effectively ...

A step-by-step guide on deploying an application using ASP.NET Core and Angular within Visual Studio

I recently completed a tutorial on integrating ASP.NET Core with Angular, which you can find at this link. After following the tutorial, I successfully set up a solution that includes both a backend ASP.NET Core and an angular client application. However ...

Angular services do not hold onto data in memory

Working on an app with a date filter and encountering an issue: I am trying to store data in my service, but when I route, the array in the service keeps resetting itself. How can I maintain the data permanently in my service? Below is the code snippet: ...

The NGRX + Resolver issue arises when the component loads before the action is fully dispatched, causing interaction problems

I'm currently facing an issue with fetching data from a route and loading it into my state before displaying my detail component. To tackle this, I've implemented a resolver. Although my get request seems to be functioning, it appears that the AP ...

Node.js - Issue: The connection unexpectedly broke

When attempting to retrieve data from the json.placeholder API using a proxy domain and authentication through an auth header, I encounter an error message that reads: error: { Error: socket hang up at createHangUpError (_http_client.js:331:15) ... at pro ...

Utilizing server-side caching middleware with tRPC version 10

Currently, I am working on a Next.js project and exploring the possibility of incorporating in-memory caching for tRPC results. Each tRPC procedure should have the option to set a custom TTL for caching purposes. My initial thought is that utilizing tRPC&a ...

There was an error encountered during the npm install process

C:\Users\Mayur Saner\pmrm>npm install npm ERR! code ENOTFOUND npm ERR! errno ENOTFOUND npm ERR! network request to http://registry.npmjs.org/@fortawesome%2ffontawesome-free failed, reason: getaddrinfo ENOTFOUND proxy.company.com npm ERR! ...

Steps for launching Angular 5 application using Node.js server

I have developed an Angular 5 application that retrieves data from a node.js server. I successfully deployed the application to my web server hosted by FastComet, which supports node.js, but unfortunately, the server does not seem to be functioning properl ...

Unit testing in Angular - creating mock services with observables

I'm currently facing an issue with my unit tests for a component that subscribes to an Observable from the service DataService in the ngOnInit() lifecycle hook. Despite my efforts, I keep encountering the error message TypeError: Cannot read propertie ...

Trigger a call on a chosen date by utilizing the mat-date-range-picker component with mat-date-range-picker-actions

My goal is to utilize the angular material date picker feature to connect my dates with angular reactive forms. In a typical scenario, when I use the date picker functionality, selecting a date immediately triggers a change in the formControl upon interact ...

Sending a dictionary and a file using Ajax is a useful feature when developing web

Within my HTML code, I have a single file (without a form tag) <input id="file1" type="file" class="form-control form-exception"> along with several textboxes <input id="id-one" type="text" class="form-control" > <input id="id-two" type=" ...