We are porting one of our solutions to PCL but face with lots of problems regarding supported classes and properties of NET framework base class libraries. to make same same functionality to work across different platforms we implemented WebClient but we do not see status code property in WebRespornce class.
before I post code sample let me emphasize platform we are targeting at the moment.
The framework version is 4.5 the platforms we are targeting are; Windows Phone 8 Windows 8 (RT) Windows 7/8 with WPF application.
here is the code we are using but cloud not find StatusCode property inside WebResponce
private static byte[] ReadStreamFromResponce(WebResponse result)
{
using (var responseStream = result.GetResponseStream())
using (var ms = new MemoryStream())
{
if (responseStream != null) responseStream.CopyTo(ms);
return ms.ToArray();
}
}
private static Task<byte[]> MakeAsyncRequest(string requestString)
{
var request = (HttpWebRequest)WebRequest.Create(requestString);
Task<WebResponse> requestTask = Task.Factory.FromAsync(
request.BeginGetResponse,
asyncResult => request.EndGetResponse(asyncResult),
null);
return requestTask.ContinueWith(t => ReadStreamFromResponce(t.Result));
}
The property is in the HttpWebResponse
class (which is derived from WebResponse
), not in the base class.
You need to cast the result to the appropriate derived class to access the status code.