Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed iOS bug where resend = no body #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions src/ModernHttpClient/iOS/NSUrlSessionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,15 @@ ProgressDelegate getAndRemoveCallbackFromRegister(HttpRequestMessage request)
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var headers = request.Headers as IEnumerable<KeyValuePair<string, IEnumerable<string>>>;
var ms = new MemoryStream();
byte[] contentBytes = null;

if (request.Content != null) {
await request.Content.CopyToAsync(ms).ConfigureAwait(false);
contentBytes = await request.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
headers = headers.Union(request.Content.Headers).ToArray();
}

var rq = new NSMutableUrlRequest() {
AllowsCellularAccess = true,
Body = NSData.FromArray(ms.ToArray()),
CachePolicy = NSUrlRequestCachePolicy.UseProtocolCachePolicy,
Headers = headers.Aggregate(new NSMutableDictionary(), (acc, x) => {
acc.Add(new NSString(x.Key), new NSString(String.Join(",", x.Value)));
Expand All @@ -97,6 +96,9 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
HttpMethod = request.Method.ToString().ToUpperInvariant(),
Url = NSUrl.FromString(request.RequestUri.AbsoluteUri),
};
if (contentBytes != null) {
rq.Body = NSData.FromArray(contentBytes);
}

var op = session.CreateDataTask(rq);

Expand Down