wadewegner / Force.com-Toolkit-for-NET

The Force.com Toolkits for .NET provides an easy way for .NET developers to interact with the Force.com & Chatter REST APIs using native libraries.
BSD 3-Clause "New" or "Revised" License
374 stars 396 forks source link

More detail needed on setting HTTP headers #414

Open lukewlms opened 2 years ago

lukewlms commented 2 years ago

I've read https://github.com/wadewegner/Force.com-Toolkit-for-NET/issues/186, but I'm still having trouble setting a header. I've created an httpClient but how do I "pass it in" here, is this supported?

As soon as I add this code (including without any header set), I get an error like this, which makes it seem like passing in the HTTP Header isn't working at all:

value": "

System.AggregateException: One or more errors occurred. (Unexpected character encountered while parsing value: <. Path '', line 0, position 0.)\n ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.\n   at 

(My ultimate goal is to enable field truncation for a request, so we don't need to custom truncate every single field at the perfect length, per https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_header_allowfieldtruncation.htm.)

Here's the code. Note that I'm not sure this is the right header naming for this option, I haven't found SF documentation for setting it via HTTP:

    var httpClient = new HttpClient();
    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Allow-Field-Truncation", "true");

    var client = new ForceClient(
      instanceUrl: auth.InstanceUrl,
      accessToken: auth.AccessToken,
      apiVersion: auth.ApiVersion,
      httpClient,
      httpClient
    );

(It looks like part of the issue I'm facing, at least, is the same as: https://github.com/wadewegner/Force.com-Toolkit-for-NET/issues/377)

muenzpraeger commented 1 year ago

I'm not familiar with .NETet al, but this library seems to only support the REST APIs.

The mentioned AllowFieldTruncationHeader is a SOAP header (as you linked), not a HTTP header.