ramesh rammi

ramesh rammi

  • NA
  • 86
  • 14.1k

How to pass the header, body data while using postmethod api

Nov 20 2018 3:06 AM

i have two methods in webapi .one method is used for passing the data through the body at the time i can possible to pass through body in json format and also another method for passing the data through header in json format but i need to combine both json response to single jsonobject format how can do this.many of examples i seen it's not worked for me.please help me.

Body data code:
  1. [Httppost]  
  2. [Route("api/Account/Login")]  
  3. public async task Login([From body]LoginRequest request)  
  4. {
  5.  return response;  
  6. }  
Header data code:
  1. private HttpWebRequest CreateRequestObject(string ServiceURL)  
  2. {  
  3.    HttpWebRequest request=null;  
  4.    try  
  5.    {  
  6.       var _authkey=configurationManger.APPSetting["userkey"];  
  7.       request=(HttpWebRequest)WebRequest.Create(ServiceURL)  
  8.       request.Method="Post";  
  9.       request.ContentType="Application/Json";  
  10.       request.Headers.Add("AuthKey",_authkey);  
  11.    }  
  12.    catch(Exception ex)  
  13.   {  
  14.   }  
  15.  return request  
  16.   
  17. }  
please help me,
Thank u.

Answers (2)