473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Error 500 (Internal Server Error) between API Laravel 5.4 and Angular 2

When i post form angular form to API Laravel i get error 500 (Internal Server Error) in console .... why?

Note: Backend API is working perfectly with POSTMAN.

My Cors.php in Laravel is:

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');
}
}
and 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);
}
}
and 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));
}
}
and register.component.html is:

<!-- 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 i need resolve this problem ... thanks alot
Mar 3 '17 #1
0 2146

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ralph | last post by:
HTTP 500 - Internal server error ASP pages I am running Windows 2K with IIS 5.1 and I started having problems accessing ASP databases shortly after applying the MS patch Windows 2000 Hotfix...
10
by: | last post by:
I am accessing the same error-containing ASP page on an ISP server using w2k IE6 but with different effect. On the first computer I get several line of HTML outputed by ASP, shown correctly by...
5
by: Ben | last post by:
hi when I try to excecute an ASP (either JS or VB) script to say, access a database record, I get an Internal Server Error HTTP 500.100 Why? and HOW CAN I FIX THIS? Thanks
4
by: Patrick Masson | last post by:
Hello, Our configuration : Apache 2.0.53 PHP 5.0.4 PC Windows 2000 MATLAB 6.1 We work on a consulting project in France which involves MATLAB Web server,
6
by: AlanS | last post by:
I have used Visual Studio for about 8 months. I have developed some ASP solutions. I had to get on with some other things and have not worked with ASP.NET for a couple months. In the meantime, I...
9
by: Trint Smith | last post by:
I have tried everything...aspreg -i and modifying machine.config and running the fileupdate...deleting and reinstalling framework 1.1... It only happens when I do a 'Copy Project' to the...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
4
by: jf li | last post by:
I have a Asp.net web application and a Asp.net Web service application. The Web application is using HtmlInputFile to get a 50M size of file selected by end user, read the data of this file and...
11
by: Lieven | last post by:
Hey, I had a hard disc problem last week on my server. I replaced the disc and copied al the files to the new hard disc, everything works fine again except some php scripts that are using the...
1
by: saipavan | last post by:
Please go through the following fix this error. 1. Click on http://www.athensys.com/giorgio/search_gallery.php and enter any keyword (or) word in the main search bar " Search here for Google...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.