Bug 11372 - HttpContent.ReadAsAsync extension
Summary: HttpContent.ReadAsAsync extension
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.7.x
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2013-03-23 09:19 UTC by Mikkel
Modified: 2017-09-01 18:33 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:
RESOLVED INVALID

Description Mikkel 2013-03-23 09:19:56 UTC

    
Comment 1 Mikkel 2013-03-23 09:30:44 UTC
Hmm. The report got submitted somehow before I was done writing it.

Anyway, this is more an enhancement request.

I was in need of ReadAsAsync (extension in System.Net.Http.Formatting), as I would like to handle deserialization based on the HTTP Status Code.

Someting like this (simplified):

var response = await client.PostAsync("URL", new FormUrlEncodedContent(parameters));

Debug.WriteLine("Status Code: " + response.StatusCode);

if (response.IsSuccessStatusCode) {
	this.RunOnUiThread(() => Toast.MakeText(this, "Success", ToastLength.Short).Show());
} else {

	if (response.StatusCode == HttpStatusCode.BadRequest) {

		var error = await response.Content.ReadAsAsync<ErrorResponse>();

		this.RunOnUiThread(() => Toast.MakeText(this, error.Message, ToastLength.Short).Show());
	} else {
		this.RunOnUiThread(() => Toast.MakeText(this, "Unknown Error", ToastLength.Short).Show());
	}
}

But from what I can see, there isn't a Xamarin.Android compatible assembly of System.Net.Http.Formatting available in the current alpha (4.7.1).

AFAIK it is also missing from Xamarin.iOS.
Comment 2 Radek Doulik 2013-05-06 06:22:38 UTC
Thanks for your bug report!

I see the System.Net.Http.Formatting assembly available in 4.7.5 so I suppose it is already fixed.

There are 3 read async methods in HttpContent class, ReadAsByteArrayAsync, ReadAsStreamAsync and ReadAsStringAsync, I hope these are what you are looking for.
Comment 3 Radek Doulik 2013-05-06 06:29:49 UTC
Ops, I noticed you were asking about System.Net.Http.Formatting and not System.Net.Http
Comment 4 Jon Douglas [MSFT] 2017-09-01 18:33:46 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.