Angular2 HTTP Post ASP.NET MVC Web API

前端 未结 7 1806
栀梦
栀梦 2020-12-06 11:23

How do you properly create a Web API POST of complex object or multiple parameters using Angular2?

I have a service component in Angular2 as seen below:



        
相关标签:
7条回答
  • 2020-12-06 12:11

    I have fixed the issue of Angular2 HTTP Post ASP.NET MVC Web API

    let headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
    let params: URLSearchParams = new URLSearchParams();
    params.set('value', '2');
    
    let options = new RequestOptions({
        headers: headers//,
        //search: params
    });
    let content = new URLSearchParams();
    content.set('StudentName', 'Inderjit Singh';
    content.set('Mobile', '+919041165398');            
    content.set('Nationality', 'Indian');
    content.set('AdmissionNo', '6');
    content.set('SectionCode', '1');
    content.set('Gender', 'Male');
    content.set('RegNo', '18585');
    content.set('ClassCode', '1');
    this.http.post('YOUR_URL', content.toString(), { headers: headers }).map((res: Response) => { console.log("data is==>" + res.text()); }).subscribe();
    
    0 讨论(0)
提交回复
热议问题