请求选项错误和错误请求错误

时间:2018-01-24 05:06:48

标签: angular angular5 angular-http

将邮件请求发送到服务器时出错。

我的服务器将接受JSON类型的数据。在这里,我编写了angular app来发送数据。

这是我的组件代码:

import { Component, OnInit, ViewChild } from '@angular/core';
import { FormsModule, FormGroup, FormControl } from '@angular/forms';
import {HttpModule, Http, URLSearchParams, Headers, RequestOptions} from '@angular/http';
import  'rxjs/Rx';
class Signup {
constructor(public firstName: string = '',
          public lastName: string = '',
          public email: string = '',
          public password: string = '',
          public cpassword: string = '') {
 }
}

@Component({
 selector: 'app-createuser',
 templateUrl: './createuser.component.html',
 styleUrls: ['./createuser.component.css']
 })
 export class CreateuserComponent implements OnInit {
 data;
 data1='test';
  model: Signup = new Signup();
  url = "http://ewalltechnologies.in/m2/ecommerce/rest/V1/customers";
  @ViewChild('f') form: any;
  constructor(private http: Http) { }

   ngOnInit() {
   }

   onSubmit() {
   if (this.form.valid) {
     console.log("Form Submitted!");
  let cust:any={'email':this.model.email,'firstname':this.model.firstName,'lastname':this.model.lastName};
 let test={'customer':cust,'password':this.model.password};
  this.data=test;
 let search = new URLSearchParams();
 search.set('username', 'nagaraju.k@ewallsolutions.com');
 search.set('password', 'ewall@123');
 this.http.post("http://ewalltechnologies.in/m2/ecommerce/rest/V1/integration/customer/token",{username:'nagaraju.k@ewallsolutions.com',password:'ewall@123'}).subscribe(res => console.log(res.json()))
 this.test().subscribe(res => console.log(res),
 err => console.log(err),
 () => console.log("Done") );
}
 }
 test()
 {
   let body = this.data;
  let headers: Headers = new Headers();
  headers.append('Content-Type', 'application/json');
  let opts: RequestOptions = new RequestOptions();
  opts.headers = headers;
   return this.http.post(this.url, body,opts).map(res => res.json());
}
}

这是我在传递请求后得到的错误。

  

阻止跨源请求:同源策略禁止在http://ewalltechnologies.in/m2/ecommerce/rest/V1/integration/customer/token读取远程资源。 (原因:CORS预检频道没有成功)。

     

阻止跨源请求:同源策略禁止在http://ewalltechnologies.in/m2/ecommerce/rest/V1/customers读取远程资源。 (原因:CORS预检频道没有成功)。

0 个答案:

没有答案