Skip to content

Commit 2b3fc02

Browse files
committed
Add empty content if there's no content but there are content headers
1 parent 2e152ec commit 2b3fc02

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/RestSharp/Request/RequestContent.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ void AddHeaders() {
142142
.Where(x => x.Type == ParameterType.HttpHeader && ContentHeaders.Contains(x.Name))
143143
.ToArray();
144144

145-
if (contentHeaders.Length > 0 && Content == null)
146-
throw new InvalidRequestException("Content headers should not be used when there's no body in the request");
147-
145+
if (contentHeaders.Length > 0 && Content == null) {
146+
// We need some content to add content headers to it, so if necessary, we'll add empty content
147+
Content = new StringContent("");
148+
}
148149
contentHeaders.ForEach(AddHeader);
149150

150151
void AddHeader(Parameter parameter) {

0 commit comments

Comments
 (0)