net :: ERR_CONNECTION_REFUSED в функции post angular8 - PullRequest
0 голосов
/ 30 апреля 2020

Я новичок в Angular и пытаюсь отправить данные клиента на сервер с помощью функции post, и я получаю эти сообщения

  1. zone-evergreen. js: 2845 POST http://localhost: 11818 / api / Login / UserLogin net :: ERR_CONNECTION_REFUSED

  2. core. js: 6185 ОШИБКА HttpErrorResponse {заголовки: HttpHeaders, статус: 0, statusText: «Неизвестная ошибка», URL: «http://localhost: 11818 / api / Login / UserLogin », ok: false,…}

this это login.ts:

import { Component, OnInit } from '@angular/core';
import { AjaxService } from '../services/ajax.service';
import {HttpClient,HttpParams} from '@angular/common/http';
import { FormGroup, FormControl, Validators } from '@angular/forms';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
  loginform:FormGroup
  constructor(private http:AjaxService,private httpClient:HttpClient) {
    this.loginform= new FormGroup({
      password:new FormControl("",[Validators.required,Validators.minLength(8)]),
      email:new FormControl("",[Validators.email,Validators.required])
  });
}
  ngOnInit(){
  }

  login(){
    return this.http.login(this.loginform.value).subscribe(data => {    
        console.log(data.Message)  
      }     
    });    
};   

ajax service.ts

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



@Injectable({
  providedIn: 'root'
})
export class AjaxService {
  Url :string;  
  token : string;  
  header : any; 
  constructor(private http:HttpClient) {
    this.Url = 'http://localhost:11818/api/Login/'; 
    const headerSettings: {[name: string]: string | string[]; } = {};  
    this.header = new HttpHeaders(headerSettings);  
  }


  login(user : any){    
    return this.http.post<any>(this.Url+'UserLogin',user,{ headers: this.header});  
   }  

}

angular. json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "volunteers": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/volunteers",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/styles.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "volunteers:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "volunteers:build:production"
            }
          }
        },

        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "volunteers:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/styles.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "volunteers:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "volunteers:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "volunteers",
  "cli": {
    "analytics": "73eb5054-29e1-4f9d-a11f-63b1b27ed08b"
  }
}

Я буду вам благодарен, если Вы можете помочь мне !!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...