Angular制作http帖子不起作用

时间:2018-07-12 21:02:30

标签: angular http http-post http-get

我正在尝试在Angular中发出http发布请求,但不知道为什么它不起作用。

For Each dataRow As DataRow In ds.Rows
    For Each dataColumn As DataColumn In ds.Columns
        For Each pt As Web.UI.DataVisualization.Charting.DataPoint In Chart1.Series("Series1").Points
            If (dataRow("ColorID").ToString() = "0") Then
                pt.Color = Drawing.ColorTranslator.FromHtml("#ff4000")
            ElseIf (dataRow("ColorID").ToString() = "1") Then
                pt.Color = Drawing.ColorTranslator.FromHtml("#e6e600")
            ElseIf (dataRow("ColorID").ToString() = "2") Then
                pt.Color = Drawing.ColorTranslator.FromHtml("#009933")
            End If
        Next
    Next
Next

我已注释掉密码和用户名,但出现401错误,无法弄清楚为什么我使用的凭据正确,因为它们是通过邮递员工作的。也许我发出的POST请求不正确?

2 个答案:

答案 0 :(得分:0)

尝试使用此功能发布请求

     getTripEstimate(event){
            this.http.post("http://localhost:8000/auth/oauth/token",{
      **use what ever params you want to send**
              "username": "*****",
              "password": "*****"
            },
              { headers: headers})
              .subscribe(response => {
               console.log(response);
          }

答案 1 :(得分:0)

您没有正确建立请求:

HttpClient的正确构造函数是httpClient.post(url, body, options)

this.http.post(
  "http://localhost:8000/auth/oauth/token",
  body,
  headers: headers
).subscribe(res => { console.log(res); }, error => console.log(error))