HttpClient Post Async call

387 Views Asked by At

I am trying to call a Windchill Odata rest service. THE HTTP GET method works fine, but it is not working as expected when making a POST request. I am also not sure how to pass the required parameter to the URL. Any suggestions will help a lot.

URL that I am trying to call

http://Hostname/Windchill/servlet/odata/v3/ProdMgmt/Parts('OR:wt.part.WTPart:123456')/PTC.ProdMgmt.GetPartStructure?$expand=Components($select=PartName,PartNumber;$expand=PartUse($select=FindNumber,LineNumber,Quantity,Unit);$levels=1)

Parameter that need to be passed to the URL is ('OR:wt.part.WTPart:123456'). I am doing this in C# .NET.

My C# code

using (var client = new HttpClient())
 {
  client.DefaultRequestHeaders.Accept.Add(new 
 MediaTypeWithQualityHeaderValue("application/json"));

  var byteArray = Encoding.ASCII.GetBytes("abc:defg!");

  client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

  client.DefaultRequestHeaders.Add("CSRF_NONCE", a.NonceValue);

   var message = await client.PostAsync("hostname/Windchill/servlet/odata/v3/ProdMgmt/Parts('OR:wt.part.WTPart:123456')/PTC.ProdMgmt.GetPartStructure?$expand=Components($select=PartName,PartNumber;$expand=PartUse($select=FindNumber,LineNumber,Quantity,Unit);$levels=1)", null);
  }

Any example or sample code is much appreciated.

0

There are 0 best solutions below