小编Jao*_*han的帖子

415(不支持的介质类型)角4柱

我正在尝试使用angular 4 post方法访问一个wep api。

在我的服务中,我添加了application / json的内容类型。我在将数据发送到api时将对象转换为json。我正在使用HttpClientModule

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable()

export class NewServiceService {

  baseUrl = "http://localhost:33969/api/";
  headers = { headers: new Headers({ 'Content-Type': 'application/json' }) 
      };
  obj= {
    name:"A",
    cgpa: 3
  };

_http:any;
constructor(http: HttpClient) {
    this._http = http;
}

SaveStudents(){

    this._http
    .post(
        this.baseUrl + 'home/Save', 
        JSON.stringify(this.obj),
        this.headers
     )
  .subscribe(
    res => {
      alert("Student Saved!");
    },
    err => {
      alert("Error!");
    }
  );
}}
Run Code Online (Sandbox Code Playgroud)

在API中,

using Entity;
using Microsoft.AspNetCore.Mvc;
using …
Run Code Online (Sandbox Code Playgroud)

asp.net-core-webapi angular4-httpclient

6
推荐指数
2
解决办法
1万
查看次数

Node JS:ReferenceError:require未定义

我想使用MySQL数据库.我用命令安装了MySQL npm i mysql.为了使用它,我写道:

var mysql = require('mysql');
Run Code Online (Sandbox Code Playgroud)

但是当我运行程序时,它显示ReferenceError:require未定义错误.

我在脚本标记中的home.ejs文件中写了这一行.

javascript node.js

5
推荐指数
1
解决办法
7550
查看次数