简体   繁体   English

Http post 405方法不允许

[英]Http post 405 Method Not Allowed

Apologize if this is a newbie question or for using inaccurate terminology. 如果这是一个新手问题或使用不准确的术语,请道歉。 coz I am a newbie. 因为我是新手。

I built a simple python api to read and write into a database (csv file) my front end is Angular 5. I managed to get the data in full from the file on the server, but I cannot post to it. 我构建了一个简单的python api来读取和写入数据库(csv文件)我的前端是Angular 5.我设法从服务器上的文件中完整地获取数据,但我无法发布到它。 Here is the issue (it seems!) 这是问题(似乎!)

The method I am using is post and the data is an array of JSON. 我使用的方法是post,数据是JSON数组。

This is the code of interest: component.ts side: 这是感兴趣的代码:component.ts方:

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

services.ts side: services.ts方面:

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

Error I am getting is 405 Method Not Allowed and console's Network shows: 我得到的错误是405方法不允许,控制台的网络显示:

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

Everything works fine using postman, the URL seems to be correct but the issue seems to be with the data itself. 使用邮递员一切正常,URL似乎是正确的但问题似乎与数据本身有关。

I tried these: 我试过这些:

This did NOT work: 这不起作用:

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

but this DID work: 但是这个DID工作:

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

and this DID work: 这个DID工作:

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

I believe the data that I am trying to post is also in this exact format, a JSON array. 我相信我试图发布的数据也是这种格式,一个JSON数组。

Any assistance is greatly appreciated. 非常感谢任何帮助。

405 indicates something wrong with your script. 405表示您的脚本有问题。 Considering one version works, its unlikely to be the web server. 考虑到一个版本有效,它不太可能是Web服务器。 You need to have the [] brackets for this type. 您需要为此类型设置[]括号。

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

相关问题 405(不允许的方法)用于角度的 POST 方法 - 405 (Method Not Allowed) for POST method in angular 405(不允许使用方法)使用Angular httpClient POST - 405 (Method Not Allowed) using Angular httpClient POST 尝试 POST 时错误 405 方法不允许 - Error 405 Method Not Allowed when trying to POST 从angular到web api发出http post请求时,405方法不允许错误 - 405 method not allowed error when making http post request from angular to web api Angular metronic 模板错误 - Http 故障响应:405 Method Not Allowed - Angular metronic template error - Http failure response : 405 Method Not Allowed 角度:HTTP GET请求-选项405(不允许使用方法) - Angular: HTTP GET request - OPTIONS 405 (Method Not Allowed) Angular Web Api 2 不适用于 POST:405 Method Not Allowed - Angular Web Api 2 is not working with POST : 405 Method Not Allowed “无法在已发布的 Web API 上发布数据” – 405(不允许的方法) - “Not able to post data on published Web API” – 405 (Method Not Allowed) Angular 7:发送 post 请求给出错误 405(不允许的方法) - Angular 7: Sending post request gives error 405 (Method not allowed) 从Angular 2应用程序发布POST时c# - 405(方法不允许) - c# - 405 (Method Not Allowed) when POST from Angular 2 app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM