Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Frends.Community.Multipart.SendMultipartRequest/Definition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public class TextData
/// Value for the header.
/// </summary>
public string Value { get; set; }

/// <summary>
/// Type of text data.
/// </summary>
[DefaultValue(TextType.String)]
public TextType ContentType { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -189,3 +195,12 @@ public enum HttpMethod
POST,
PUT
}

/// <summary>
/// Enum for selecting text data type.
/// </summary>
public enum TextType
{
String,
JSON
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageTags>Frends</PackageTags>
<Description>Frends task for sending multipart/form-data requests.</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>1.3.0</Version>
<Version>1.4.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ public static async Task<SendResult> SendMultipartRequest(
foreach (var text in input.TextData)
{
cancellationToken.ThrowIfCancellationRequested();
request.AddParameter(text.Key, text.Value, ParameterType.GetOrPost);
if (text.ContentType.ToString() == "JSON")
{
BodyParameter bodyParameter = new BodyParameter(text.Key, text.Value, "application/json");
request.AddParameter(bodyParameter);
}
else
request.AddParameter(text.Key, text.Value, ParameterType.GetOrPost);
}

foreach (var header in input.Headers)
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ A frends task for sending multipart/form-data requests.

### Input

| Property | Type | Description | Example |
|-----------|---------------------------------------------------------|-------------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| Method | `Enum<POST, PUT>` | HTTP method which should be used for the multipart/form-data request. | `POST` |
| Url | `string` | Target URL. | `https://httpbin.org/post` |
| FilePaths | `Array(Object<enum FileParameterKey, string FullPath>)` | List of files which will be sent to the target server. | `FileParameterKey = file, FullPath = C:\tmp\test.txt` |
| Headers | `Array(Object<string Name, string Value>)` | List of headers for the request. No need to add Content-Type, since it is always multipart/form-data. | `Name = Accept, Value = application/json` |
| TextData | `Array(Object<string Key, string Data>)` | List of custom parameters for the request. | `Key = channel, Value = G01QH4ES8SY` |
| Property | Type | Description | Example |
|-----------|-------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| Method | `Enum<POST, PUT>` | HTTP method which should be used for the multipart/form-data request. | `POST` |
| Url | `string` | Target URL. | `https://httpbin.org/post` |
| FilePaths | `Array(Object<enum FileParameterKey, string FullPath>)` | List of files which will be sent to the target server. | `FileParameterKey = file, FullPath = C:\tmp\test.txt` |
| Headers | `Array(Object<string Name, string Value>)` | List of headers for the request. No need to add Content-Type, since it is always multipart/form-data. | `Name = Accept, Value = application/json` |
| TextData | `Array(Object<string Key, string Data, enum<ContentType>>)` | List of custom parameters for the request. | `Key = channel, Value = G01QH4ES8SY, ContentType = String` |

### Options

Expand Down Expand Up @@ -100,3 +100,4 @@ NOTE: Be sure to merge the latest from "upstream" before making a pull request!
| 1.1.0 | Fixed error message and added param ThrowExceptionOnErrorResponse |
| 1.2.0 | Added option to select which file parameter key will be used. Changed timeout from double to int for UI improvement. |
| 1.3.0 | Added option to select which HTTP method should be used for the request. |
| 1.4.0 | Added support for application/json data in Text data. |
Loading