CLR - Http Headers question

Started by stanl, September 29, 2020, 06:57:49 AM

Previous topic - Next topic

stanl

Having used both CLR WebRequest and HttpClient to connect to a web URL, I got interested in Headers.


using System.Net.Http.HttpClient
Code (WINBATCH) Select


oClient.DefaultRequestHeaders.Add("User-Agent","Other")
oClient.DefaultRequestHeaders.Add("Accept","application/geo+json")



works, and for System.Net.WebRequest


Code (WINBATCH) Select


request.UserAgent = "Other"
request.ContentType = "application/geo+json"



works as well


but  oClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); [in C#] but cannot convert to WB CLR fails

which requires  ObjectClrOption("useany", "System.Net.Http.Headers") as a namespace, but I cannot instantiate that in WB, error that assembly cannot be found or loaded.

Guess a little clarification on how a request for Content-Type and other headers might be handled with HttpClient?

td

"System.Net.Http.Headers" is a namespace and not an assembly and "HttpHeaders" is an abstract class.  You could do something like the following:

Code (winbatch) Select
ObjectClrOption("useany", "System.Net.Http")
objHeaders = ObjectClrNew('System.Net.Http.Headers.MediaTypeWithQualityHeaderValue')


But that is about it.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl