2017-03-02 3 views
0

Wenn ich Formular eckige Form zu API Laravel poste, erhalte ich Fehler 500 (Interner Serverfehler) in der Konsole .... warum?Fehler 500 (Interner Serverfehler) zwischen API Laravel 5.4 und Angular 2

Hinweis: Back-End-API funktioniert perfekt mit POSTMAN.

Mein Cors.php in Laravel ist:

namespace App\Http\Middleware; 

use Closure; 

class Cors 
{ 
/** 
* Handle an incoming request. 
* 
* @param \Illuminate\Http\Request $request 
* @param \Closure $next 
* @return mixed 
*/ 
public function handle($request, Closure $next) 
{ 
    return $next($request) 
    ->header('Access-Control-Allow-Origin', '*') 
    ->header('Access-Control-Allow-Credentials','true') 
    ->header('Access-Control-Allow','GET,POST,PUT,PATCH,DELELE,OPTIONS') 
    ->header('Access-Control-Allow-Headers','Content-Type, Authorization,X-XSRF-TOKEN,X-CSRF-TOKEN','CSRF-TOKEN','XSRF-TOKEN'); 
    } 
} 

und in register.component.ts:

import { Component,OnInit,Input } from '@angular/core'; 
import { Router } from '@angular/router'; 
import { NgForm } from '@angular/forms'; 
import { UserService } from '../../services/user.service'; 

@Component({ 
    styleUrls: ['../../templates/users/register.component.css'], 
    templateUrl: '../../templates/users/register.component.html', 
}) 

export class RegisterComponent { 
title = 'register'; 

constructor(private _router: Router,private UserService: UserService){ 

} 

ngOnInit() { 

} 
onSubmit(form:NgForm){ 
    this.UserService.register(form.value); 
    } 
} 

und user.service.ts:

import { Injectable } from '@angular/core'; 
import { Http,Response,Headers } from '@angular/http'; 
import 'rxjs/Rx'; 
import { Observable } from 'rxjs'; 


    @Injectable() 
    export class UserService{ 
    constructor(private http: Http){ 

    } 

    register(data : Object){ 
    const body = JSON.stringify({data:data}); 
    const headers = new Headers({'Content-Type':'application/json'}); 
    return this.http.post('http://localhost/etqan/etqan_lara/public/api/user',body,{headers:headers}).subscribe((data2) => console.log(data2)); 
    } 
} 

und registrieren component.html ist:

<!-- Header --> 
    <header> 
    <div class="container"> 
     <div class="intro-text wow fadeInDown animated"> 
      <div class="row"> 
       <div class="col-md-4 col-md-offset-4"> 
        <div class="wrap"> 
         <p class="form-title">مستخدم جديد</p> 
         <form class="login" #f="ngForm" (ngSubmit)="onSubmit(f)"> 
         <input type="text" placeholder="اسم المستخدم" name="username" ngModel /> 
         <input type="text" placeholder="البريد الالكتروني" name="email" ngModel /> 
         <input type="password" placeholder="كلمة المرور" name="password" ngModel /> 
         <input type="password" placeholder="تأكيد كلمة المرور" name="repassword" ngModel /> 
         <input type="submit" value="تسجيل" class="btn btn-success btn-sm" /> 
         </form> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</header> 
<!-- Header End --> 

pls ich brauche dieses problem zu lösen ... danke viel

+0

Interner Server Fehler bedeutet: _check Ihre Protokolldateien für Details! _ – jszobody

+0

wo kann ich es finden? – khaledbelal

+0

@khaledbelal Überprüfen Sie Ihre Backend-API, diese vielleicht "http: // localhost/etqan/etqan_lara/public/api/user". Sie können den POSTMAN-Client verwenden, um Ihre APIs zu testen, bevor Sie sie in Ihrer Frontend-App verwenden. –

Antwort

0

wenn "objekt" entfernen mein problem ist gelöst. danke

register(data){ 
const body = JSON.stringify({data:data}); 
const headers = new Headers({'Content-Type':'application/json'}); 
return this.http.post('http://localhost/etqan/etqan_lara/public/api/user',body,{headers:headers}).subscribe((data2) => console.log(data2)); 
} 
Verwandte Themen