elsa-workflows / elsa-workflows/elsa-core
Unable to use simple configuration of HttpRequest with content-type application/x-www-form-urlencoded
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
When trying to use the HttpRequest Activity with content-type application/x-www-form, I've encountered the following issue :
When using a string variable with something like `key1=value1&key2=value2`
```
The JSON value could not be converted to System.Collections.Generic.Dictionary`2[System.String,System.String]. Path: $ | LineNumber: 0 | BytePositionInLine: 425.
at System.Text.Json.ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(Type propertyType) at
System.Text.Json.Serialization.JsonDictionaryConverter`3.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TDictionary& value) at
System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue) at
System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at
System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo`1 jsonTypeInfo) at
System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options) at
Elsa.Http.ContentWriters.FormUrlEncodedHttpContentFactory.GetContentAsDictionary(Object content) at
Elsa.Http.ContentWriters.FormUrlEncodedHttpContentFactory.CreateHttpContent(Object content, String contentType) at
Elsa.Http.SendHttpRequestBase.PrepareRequest(ActivityExecutionContext context) at
Elsa.Http.SendHttpRequestBase.TrySendAsync(ActivityExecutionContext context) at
Elsa.Http.SendHttpRequestBase.ExecuteAsync(ActivityExecutionContext context) at
Elsa.Workflows.Activity.Elsa.Workflows.Contracts.IActivity.ExecuteAsync(ActivityExecutionContext context) at
Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context) at
Elsa.Workflows.Runtime.Middleware.Activities.BackgroundActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context) at
Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.InvokeAsync(ActivityExecutionContext context) at
Elsa.Workflows.Middleware.Activities.NotificationPublishingMiddleware.InvokeAsync(ActivityExecutionContext context) at
Elsa.Workflows.Middleware.Activities.ExecutionLogMiddleware.InvokeAsync(ActivityExecutionContext context)
```
If we use a Json Variable and returning this variable (tested using Javascript Code) :
```
Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at
Elsa.Http.ContentWriters.FormUrlEncodedHttpContentFactory.GetContentAsDictionary(Object content) at
Elsa.Http.ContentWriters.FormUrlEncodedHttpContentFactory.CreateHttpContent(Object content, String contentType) at
Elsa.Http.SendHttpRequestBase.PrepareRequest(ActivityExecutionContext context) at
Elsa.Http.SendHttpRequestBase.TrySendAsync(ActivityExecutionContext context) at
Elsa.Http.SendHttpRequestBase.ExecuteAsync(ActivityExecutionContext context) at
Elsa.Workflows.Activity.Elsa.Workflows.Contracts.IActivity.ExecuteAsync(ActivityExecutionContext context) at
Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context) at
Elsa.Workflows.Runtime.Middleware.Activities.BackgroundActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context) at
Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.InvokeAsync(ActivityExecutionContext context) at
Elsa.Workflows.Middleware.Activities.NotificationPublishingMiddleware.InvokeAsync(ActivityExecutionContext context) at
Elsa.Workflows.Middleware.Activities.ExecutionLogMiddleware.InvokeAsync(ActivityExecutionContext context)
```
The `FormUrlEncodedHttpContentFactory` seems to have an issue when interpreting the input.
To be userfriendly, the input should be given using :
- key value pair in string like key1=value1&key2=value2
- could be a simple json object like `{"key1"="value1", "key2"="value2" }`
Contributor guide
Research direction
Start with Elsa.Http.ContentWriters.FormUrlEncodedHttpContentFactory, using the two stack traces to inspect GetContentAsDictionary and CreateHttpContent. Reproduce the issue through the HttpRequest Activity with a key-value string and a JSON object. Done means both supported input forms create form-urlencoded content without the reported conversion exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100