WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: stanl on September 29, 2020, 06:57:49 AM

Title: CLR - Http Headers question
Post by: stanl on September 29, 2020, 06:57:49 AM
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?
Title: Re: CLR - Http Headers question
Post by: td on September 29, 2020, 08:27:04 AM
"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.
Title: Re: CLR - Http Headers question
Post by: stanl on September 29, 2020, 09:34:57 AM
Thanks.