将列表数据从angular发送到django rest

将列表数据从angular发送到django rest,angular,api,django-rest-framework,Angular,Api,Django Rest Framework,我正在学习angular,现在我想将数据数组发送到django rest框架,我尝试使用HttpParams,JSON.stringyfy(),但没有任何数据是空的 角度代码: public getSymptomsList(symptomList:string[]){ console.log(symptomList) return this.httpClient.post(`${this.ApiUrl}diagnos/`, {PASS_DATA_HERE},{headers:

我正在学习angular,现在我想将数据数组发送到django rest框架,我尝试使用
HttpParams
JSON.stringyfy()
,但没有任何数据是空的

角度代码:

public getSymptomsList(symptomList:string[]){
    console.log(symptomList)

    return this.httpClient.post(`${this.ApiUrl}diagnos/`, {PASS_DATA_HERE},{headers: new HttpHeaders().set('Authorization', `Token ${this.AuthToken}`),});

  }
Djnago API代码:

class diagnos(APIView):
    def post(self, request):
        symptomlist = request.POST.getlist('symptoms')
        print(symptomlist)
        ...
但当我尝试使用terminal by
httpie
时,它给出了以下结果:

bhupesh@Laptop:~$ http -f POST http://127.0.0.1:8000/api/diagnos/ symptoms='fever' symptoms='urinoma'
HTTP/1.1 200 OK
Allow: POST, PUT, OPTIONS
Content-Length: 5037
Content-Type: application/json
Date: Sat, 24 Oct 2020 13:38:57 GMT
Referrer-Policy: same-origin
Server: WSGIServer/0.2 CPython/3.8.5
Vary: Accept, Origin
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

[
    {
        "name": "uncoordination"
    },
    {
        "name": "fever"
    },
    {
        "name": "pleuritic pain"
    },
    {
        "name": "snuffle"
    },
    {
        "name": "throat sore"
    },
    {
        "name": "malaise"
    },
    {
        "name": "debilitation"
    }
]

尝试将您的请求转换为:

public getSymptomsList(symptoms:string[]){

    return this.httpClient.post(`${this.ApiUrl}diagnos/`, {symptoms},{headers: new HttpHeaders().set('Authorization', `Token ${this.AuthToken}`),});

  }
使用此代码,主体将是一个具有字段符号的对象

{
"symptoms": ["a","b","c"]
}

当请求完成时,您在“网络”选项卡中看到了什么?即使我打印了请求,请求也会成功执行。其中的body会打印列表,但不会作为post数据发送