Post request posting null #1402

Closed
opened 2025-08-09 17:20:00 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @AndrewKralovec on 9/2/2016

I'm trying to make a post request in Angular2 using your project generator. For some reason I cant make POST request. I changed both the client and server to GET request and left everything else the same, and it works fine. The template project you guys have all the GET request work fine, but if i do POST it sends null data. I'm wondering if this a common bug with the project because i follow all the anuglar2/asp.net core documents and i dont know whats wrong.

Example Code
Client.ts

search(username: any, password: any){
        let headers = new Headers(); 
        headers.append('Content-Type', 'application/json'); 
        let body = JSON.stringify({ username, password });
        this.http.post('/api/SampleData/find',body, { headers: headers })
        .map(response => response.json())
        .subscribe(
            data =>  this.Debug(data),
            err =>  console.log("Error: \n"+err),
            () => console.log('Get Complete')
        ); 
}

Server.cs

[HttpPost("[action]")]
    public async Task<IActionResult> find(string user)
    {
        var test = user; // NULL
        // search DB
        return Json(test); 
    }
*Originally created by @AndrewKralovec on 9/2/2016* I'm trying to make a post request in Angular2 using your project generator. For some reason I cant make POST request. I changed both the client and server to GET request and left everything else the same, and it works fine. The template project you guys have all the GET request work fine, but if i do POST it sends null data. I'm wondering if this a common bug with the project because i follow all the anuglar2/asp.net core documents and i dont know whats wrong. Example Code **Client.ts** ``` search(username: any, password: any){ let headers = new Headers(); headers.append('Content-Type', 'application/json'); let body = JSON.stringify({ username, password }); this.http.post('/api/SampleData/find',body, { headers: headers }) .map(response => response.json()) .subscribe( data => this.Debug(data), err => console.log("Error: \n"+err), () => console.log('Get Complete') ); } ``` **Server.cs** ``` [HttpPost("[action]")] public async Task<IActionResult> find(string user) { var test = user; // NULL // search DB return Json(test); } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1402
No description provided.