Add HttpClient support in Portable Class Libraries (including Windows Phone 8)
We’re happy to announce that we shipped a public beta. More details are available here:
Patrick Dengler commented
There is an issue with the Http PCL implementation (and I tried the beta as well) whereas form fields with brackets are rejected. I understand why, but it is a common pattern for SAAS sites. http://social.msdn.microsoft.com/Forums/windowsapps/en-US/d1040cc3-1f12-419b-b3db-81eb45dff5d3/multiformdatacontent-fails-on-pcl-for-systemnethttp-when-using-names-that-contain-brackets-eg?forum=winappswithcsharp
Is there any chance this could be fixed?
Is there any way to track progress of the request using PCL WebRequest?
Ryan Riley commented
Any chance the platform restriction could be lifted so the library could be used in cross-platform libraries such as the FSharp.Data type providers?
Immo Landwerth (MSFT) commented
Gabriel, this inconsistency comes from the phone's underlying networking stack. On desktop this exception originates from the socket layer which has the context of SocketError.AbortedConnection. On phone we get a WebException, but handle it since the response exists with a status code. Unfortunately, the reponse doesn't have enough context to mimic the exception. The state returned in HttpWebResponse is the same for an aborted connection as it is for a non-existant server, among other errors. So while in theory we could throw try to throw an exception we would provide inconsistent behavior in other cases. So I'm afraid there is no way for us fix this without making other cases worse.
Gabriel S. commented
There is a problem and inconsistency when it comes to request failures. On Windows Phone 8, when a request fails to reach the server, the HttpResponseMessage can be successfully retrieved and has the IsSuccessstatusCode property set to false.
On .Net 4.5 Full and Windows Store Apps types of projects, the behaviour is instead to throw an HttpRequestException - which to me seems the correct and natural way - when this line of code is executed:
var response = await httpClient.PostAsync(uri, content);
I'm not sure if it's due to the WP8 http implementation or due to the portable HttpClient, but it's a quite unpleasant inconsistency. Do you think it can be fixed?
Rick DeMaio commented
Having trouble with Win8 Phone. Always hangs on .Result. or the last async call. Standard .net 4.5 worked like a champ without the portable stuff. I tried 5 different patterns of ContinueWith, .Result, Send, Post, Get, Wait and everything hangs. the Task says waiting for activation. MSHTTP is 2.1.10, BCL Build is 1.07, BCL Port is 1.0.19
Chris, it sounds like you've installed this version of HttpClient: http://nuget.org/packages/Microsoft.Net.Http/2.0.20710.0, when you need to install this version: http://nuget.org/packages/Microsoft.Net.Http/2.1.6-rc.
NuGet by default won't show prereleases, so you need to change this via the drop down on the Managed NuGet packages dialog.
I don't understand? How do I know what version nuget is? It is fully patched up to date. And I see only one listing for this package in there which is Version: 2.1.20710.0
Chris, it sounds like you are installing the RTM 2.0 version instead of the 2.1 RC. Also make sure you have NuGet 2.1 installed.
I can't get this to install. It says Microsoft.Net.Http could not be installed because it is not compatible with any project in the solution. The package targets .NETFramework, Version 4.5, 4.0
I had just created a new project for Windows Phone 8, using VS2012.. so what's the problem?
Dominic: Sounds like you are hitting http://support.microsoft.com/kb/2840147. Either repair VS Update 2 - or install the RC of VS Update 3.
Dominic Ferland commented
It work great for me until i install the Visual Studio 2012 Update 2.
I'm getting this compilation error when building my portable class library:
The Type 'System.Net.HttpStatusCode' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net, Version=220.127.116.11, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
I have done the test on 2 different computer... and after installing the update 2... the solutions dont compile anymore.
Have you seen that before ?
Alexander Gnauck commented
I need to connect to https sites which self signed certificates, or signed by a CA which is not trusted by Windows Phone by default. Is there solution using this library, or is this on the roadmap?
or is this only a wrapper to HttpWebRequest which does not support this feature on Windows Phone?
Xavier: The project is still alive. By "barfed" what do you mean? Didn't install? If so, try upgrading your version of NuGet to the latest.
xavier rigau commented
Is this project still alive? I tried to download it for a Windows Phone 8 solution and it barfed.
Ricardo Wickel commented
I'm also waiting for System.Net.Http.Formatting
Tony Tedeschi commented
I was hoping that the full HttpClient would have been in the mix. I would love to consume JSON content from a Web API site. The full client supports PutAsJsonAsync<T>(...) which could enable a windows phone device to consume a web api with very minimal traffic.
Is the full HttpClient being considered? It would be great to leverage the super light weight data flows from the JSON in the ew WebApi framework.
Michael Lant commented
Please make sure that it supports the .result capability to force the call to be synchronous. This is a very important construct that allows the entire call stack to be wrapped inside of a Task.run() call. It makes the whole async isssue drop-dead simple.
Thanks.. that's a fantastic news for any .NET developer!
@Rui Marinho, follow the blog link and read it. It sates that WP7.5+ is supported. So YES they didn't forget about 7.5!
영재 김 commented
God bless you,Kean.
I'm impressed to hear good news :)