I am developing a simple Angular 2 reactive form. I am using ASP.NET and SQL server as my backend to store form data. I send the form data from angular 2 using angular service to asp.net page, there I can't able to read those form data.
This is my angular code to send form data.
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/catch';
import { User } from './signup.interface';
@Injectable()
export class SignupService {
headers: Headers;
options: RequestOptions;
private producturl = "http://172.21.41.70:8081/DB-Connect/";
constructor(private _http: Http) {
this.headers = new Headers({
'Content-Type': 'application/json'
});
this.options = new RequestOptions({ headers: this.headers });
}
postDetails(user: User): Observable<User[]> {
// console.log(user);
let body = JSON.stringify(user);
console.log(body);
return this._http.post(this.producturl, body, this.options)
.map((response: Response) => response)
.do(data => console.log(JSON.stringify(data)))
.catch(this.handleError);
}
/*private extractData(res: Response) {
console.log(res);
let body = res.json();
return body || {};
}*/
private handleError(error: Response) {
console.log(error);
return Observable.throw(error.json().error());
}
}
This my asp.net code
Response.ContentType = "text/plain";
using (WebClient wc = new WebClient())
{
var json = wc.DownloadString("http://localhost:4200");
Response.Write(json);
}
While execute the code i am getting angular index page completely as a output.I am not getting any JSON data which I sent.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>
Please help me to read JSON data in asp.net page. Thanks in advance
The Angular 2 project with .NET as backend can be done with Visual studio 2017 and .NET SDK framework installed.
Thank you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.