diff --git a/sdk/core/Azure.Core/src/Shared/Multipart/MultipartContent.cs b/sdk/core/Azure.Core/src/Shared/Multipart/MultipartContent.cs
index 3604f62cb2a6f..d08f149da8118 100644
--- a/sdk/core/Azure.Core/src/Shared/Multipart/MultipartContent.cs
+++ b/sdk/core/Azure.Core/src/Shared/Multipart/MultipartContent.cs
@@ -112,7 +112,8 @@ private static string GetDefaultBoundary()
/// The request.
public void ApplyToRequest(Request request)
{
- request.Headers.Add(HttpHeader.Names.ContentType, $"multipart/{_subtype}; boundary={_boundary}");
+ request.Headers.SetValue(HttpHeader.Names.ContentType, $"multipart/{_subtype}; boundary={_boundary}");
+ request.Content = this;
}
///
diff --git a/sdk/core/Azure.Core/tests/HttpPipelineFunctionalTests.cs b/sdk/core/Azure.Core/tests/HttpPipelineFunctionalTests.cs
index a80324172f01e..c44923068fd63 100644
--- a/sdk/core/Azure.Core/tests/HttpPipelineFunctionalTests.cs
+++ b/sdk/core/Azure.Core/tests/HttpPipelineFunctionalTests.cs
@@ -404,7 +404,6 @@ public async Task SendMultipartformData()
request.Uri.Reset(testServer.Address);
var content = new MultipartFormDataContent("test_boundary");
- content.ApplyToRequest(request);
content.Add(RequestContent.Create(Encoding.UTF8.GetBytes("John")), "FirstName", "file_name.txt", new Dictionary
{
{ "Content-Type", "text/plain; charset=utf-8" }
@@ -414,7 +413,7 @@ public async Task SendMultipartformData()
{ "Content-Type", "text/plain; charset=utf-8" }
});
- request.Content = content;
+ content.ApplyToRequest(request);
using Response response = await ExecuteRequest(request, httpPipeline);
Assert.AreEqual(response.Status, 200);
diff --git a/sdk/core/Azure.Core/tests/MultipartTests.cs b/sdk/core/Azure.Core/tests/MultipartTests.cs
index 359c50f994070..0a619ffd5bb5b 100644
--- a/sdk/core/Azure.Core/tests/MultipartTests.cs
+++ b/sdk/core/Azure.Core/tests/MultipartTests.cs
@@ -184,7 +184,6 @@ public async Task SendMultipartData()
Guid batchGuid = Guid.NewGuid();
var content = new MultipartContent(Mixed, $"batch_{batchGuid}");
- content.ApplyToRequest(request);
Guid changesetGuid = Guid.NewGuid();
var changeset = new MultipartContent(Mixed, $"changeset_{changesetGuid}");
@@ -228,7 +227,7 @@ public async Task SendMultipartData()
patchReq.Content = RequestContent.Create(Encoding.UTF8.GetBytes(patchBody));
changeset.Add(new RequestRequestContent(patchReq), new Dictionary { { HttpHeader.Names.ContentType, "application/http" }, { cteHeaderName, Binary } });
- request.Content = content;
+ content.ApplyToRequest(request);
var memStream = new MemoryStream();
await content.WriteToAsync(memStream, default);
memStream.Position = 0;