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

Handle that ContentType might be null #141

Closed
wants to merge 7 commits into from

Conversation

peterno
Copy link
Contributor

@peterno peterno commented Apr 21, 2015

When using ModernHttpClient with SignalR it crashes on Android because SignalR does not set content type when posting data to the server.
If ContentType is null then string.Empty is used for MediaType.Parse and it thereby returns null and null is valid for RequestBody.Create.

Fixes #136

var contentType = String.Join (" ", request.Content.Headers.GetValues ("Content-Type"));
var contentType = string.Empty;
if (request.Content.Headers.ContentType != null)
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this bracket up to the previous line

@anaisbetts
Copy link
Owner

Great PR! I'll make these reverts go away, throw in an extra commit to fix the bracket. No need to close and resubmit!

@peterno
Copy link
Contributor Author

peterno commented Apr 22, 2015

Bracket moved, thanks for your fast response. Amazing work Paul!

@anaisbetts
Copy link
Owner

Merged by hand - thanks @peterno!

@peterno
Copy link
Contributor Author

peterno commented May 4, 2015

Unfortunately it does not work when using it with SignalR and 2.4.0. I tried to change back the OkHttp.dll to the one in 2.3.0 but that gave other errors with the Builder.

My linkersettings is None and i am using Xamarin.Andriod: 4.20.2.1 and Xamarin 3.9.547.0 in Visual Studio.

I have to switch back to 2.3.0 and my own fork of the Android version.

Stacktrace is:

Missing method Android.Runtime.JNIEnv::CallObjectMethod(intptr,intptr,JValue*) in assembly Mono.Android.dll, referenced in assembly /storage/emulated/0/Android/data/Trio.Agent/files/.__override__/OkHttp.dll
Exception: System.MissingMethodException: Method not found: 'Android.Runtime.JNIEnv.CallObjectMethod'.
  at ModernHttpClient.NativeMessageHandler+<SendAsync>c__async0.MoveNext () [0x00154] in /Users/paul/code/paulcbetts/modernhttpclient/src/ModernHttpClient/Android/OkHttpNetworkHandler.cs:96 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ModernHttpClient crashes on Android when used in SignalR
2 participants