Bug 17990 - HttpClient.PostAsync() fails when using CFNetworkHandler
Summary: HttpClient.PostAsync() fails when using CFNetworkHandler
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.0.6.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: 7.2.1
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-02-25 09:39 UTC by René Ruppert
Modified: 2014-03-21 19:34 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description René Ruppert 2014-02-25 09:39:57 UTC
I'm uploading a file to a server using the following config:

using (var oContent = new MultipartFormDataContent(sBoundary))
{
                oContent.Add(new StringContent(lFileSize.ToString()), "file_length");
                oContent.Add(new StringContent(sComment), "comment");
                oContent.Add(new StringContent(sParentPath), "parent_path");
                oContent.Add(new StreamContent(oFile), "file_attachment", sFileName);

                long fileSize = oFile.Length;
                // Post form data
            var targetUrl = GetUrl(Files_Upload);
              using (HttpResponseMessage result = await Client.PostAsync(targetUrl, oContent, cancellationToken))
...

When creating the instance of "Client" with:

Client = new HttpClient(new CFNetworkHandler())

The code above returns immediately without ever calling the server URL. 

If I change it to:

Client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate })

it is working.

* What is CFNetworkHandler()? Is the source available?
* I cannot give a you a simple self contained example.
* I would myself debug this if I had the CFNetworkHandler source.


=== Xamarin Studio ===

Version 4.3.2 (build 2)
Installation UUID: b8bdc5a1-348b-4fad-8e4f-4632ee990c59
Runtime:
	Mono 3.2.7 ((no/40f92d5)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 302070000

=== Apple Developer Tools ===

Xcode 5.0.2 (3335.32)
Build 5A3005

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.Android ===

Version: 4.12.0 (Business Edition)
Android SDK: /Users/rene/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
Java version check failed: Error creating standard error pipe

=== Xamarin.iOS ===

Version: 7.0.6.168 (Business Edition)
Hash: 2ed9bc9
Branch: 
Build date: 2014-21-01 06:33:05-0500

=== Build Information ===

Release ID: 403020002
Git revision: b442e89c84c5d1770cea90b2d69ac5e60907c578
Build date: 2014-01-30 23:06:32+0000
Xamarin addins: d8f15d9aac741cd301f6b14904d68632b0330b71

=== Operating System ===

Mac OS X 10.9.1
Darwin Renes-iMac.local 13.0.0 Darwin Kernel Version 13.0.0
    Thu Sep 19 22:22:27 PDT 2013
    root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
Comment 1 René Ruppert 2014-02-25 09:54:15 UTC
An additional note using AFNetworkHandler from Paul Bett's ModernHttpClient instead, works too. So the error really seems to be inside CFNetworkHandler.
Comment 4 Marek Safar 2014-02-26 14:05:51 UTC
It looks like we are not sending same set of headers as the other handlers. Do you have access to that server to check if there is any difference?
Comment 6 Marek Safar 2014-02-27 11:45:34 UTC
Fixed in master
Comment 7 Sadik Ali 2014-03-21 04:26:07 UTC
I have verified this issue, I run sample application with below code:

HttpClient client = new HttpClient(new CFNetworkHandler())

And Noticed that JSON value printed on console: "Result: {"body":{"fileID":47}}"
Refer screen shot: http://screencast.com/t/23qZkxjghXx

Hence I am marking this as verified.

Build Info:

=== Xamarin Studio ===
Version 4.2.4 (build 32)
Installation UUID: 449f40dd-b3f1-4028-9a6b-cca0d1a2307d
Runtime:
    Mono 3.2.6 ((no/9b58377)
    GTK+ 2.24.23 (Raleigh theme)
    Package version: 302060000

=== Apple Developer Tools ===
Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===
Version: 7.2.1.20 (Business Edition)

=== Xamarin.Android ===
Version: 4.12.3 (Business Edition)

=== Xamarin.Mac ===
Xamarin.Mac: 1.8.0.7

=== Build Information ===
Release ID: 402040032
Git revision: a160c35dac9ab9fd32eeadaa171216316d5a5133
Xamarin addins: a779416ceabd54981ce812771a4061c942e8b872

=== Operating System ===
Mac OS X 10.8.4
Darwin 360Logicas-Mac-mini.local 12.4.0 Darwin Kernel Version 12.4.0
    Sun Mar 10 18:01:10 PDT 2013
    root:xnu-2050.24.6~1/RELEASE_X86_64 x86_64
Comment 8 René Ruppert 2014-03-21 06:47:56 UTC
When will this be released? What version will it be in?
Comment 9 Rolf Bjarne Kvinge [MSFT] 2014-03-21 19:34:49 UTC
@Rene: Xamarin.iOS 7.2.1