Click here to Skip to main content
14,969,727 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have two methods.one method is used for passing the data through the body at the time i can possible to pass the body data in postman that is not problem but whenever another method used passing the data through the header in postman at the time how
header data attached to the body method while using post method.

Body data code

C#
[Httppost]
[Route("api/Account/Login")]
public async task<getbasecustomerresponse> Login([From body]LoginRequest request)
{

   
   

 return response;
}


Header data code

C#
private HttpWebRequest CreateRequestObject(string ServiceURL)
{
   HttpWebRequest request=null;
   try
   {
      var _authkey=configurationManger.APPSetting["userkey"];
      request=(HttpWebRequest)WebRequest.Create(ServiceURL)
      request.Method="Post";
      request.ContentType="Application/Json";
      request.Headers.Add("AuthKey",_authkey);
   }
   catch(Exception ex)
  {
  }
 return request

}






please help me,

Thank u.

What I have tried:

i have two methods.one method is used for passing the data through the body at the time i can possible to pass the body data in postman that is not problem but whenever another method used passing the data through the header in postman at the time how header and body method communicate to the url i.e how to use header and body method at time for service.
Posted
Updated 19-Nov-18 22:34pm
v3
Comments
Aydin Homay 19-Nov-18 17:14pm
   
Krishna you are only presenting one method could you please show how your code exactly look likes? plus rephrase your question is not really clear what you want.

1 solution

You can send data (json in this case looking at the content type) by writing the bytes (convert json string to bytes) to the request stream.

Also initialize the length of bytes in header

request.ContentLength = bytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900