i'm writing code make httpwebrequest website
if website working return httpstatuscode.ok
if not return httpstatuscode.notfound
my code
var url = "http://simplegames.com.ua/"; httpwebrequest request = (httpwebrequest)webrequest.create(url); httpwebresponse response = (httpwebresponse)request.getresponse(); if (response.statuscode == httpstatuscode.ok) { debug.writeline("all ok"); } else if (response.statuscode == httpstatuscode.notfound) { debug.writeline("url not working"); } response.close();
but have errors
1) severity code description project file line suppression state error cs1061 'httpwebrequest' not contain definition 'getresponse' , no extension method 'getresponse' accepting first argument of type 'httpwebrequest' found (are missing using directive or assembly reference?) milano c:\users\nemes\documents\github\milano_pizza\milano\mainpage.xaml.cs 50 active
2) severity code description project file line suppression state error cs1929 'httpwebresponse' not contain definition 'close' , best extension method overload 'extensionmethods.close(stream)' requires receiver of type 'stream' milano c:\users\nemes\documents\github\milano_pizza\milano\mainpage.xaml.cs 59 active
although can use httpwebrequest class in uwp apps, not of methods. httpwebrequest.getresponse method , httpwebresponse.close method methods can't used in uwp apps. usually, can find if method can used in uwp apps checking version information in bottom of document. if can find universal windows platform under version information should able use method in uwp apps.
in .net core/uwp, system.net.httpwebrequest class in system.net.requests library , not recommended use. ref. .net networking apis uwp apps:
system.net.requests
this library contains types related system.net.httpwebrequest , system.net.httpwebresponse classes allow developers implement client role of http protocol. api surface .net core 5 same available windows 8.1 apps , limited compared surface in .net framework. intentional , highly encourage switching httpclient api instead – our energy , innovation focused going forward.
this library provided purely backward compatibility , unblock usage of .net libraries use these older apis. .net core, implementation of httpwebrequest based on httpclient (reversing dependency order .net framework). mentioned above, reason avoid usage of managed .net http stack in uwp app context , move towards httpclient single http client role api .net developers.
and in uwp, have 2 httpclient apis, system.net.http.httpclient , windows.web.http.httpclient. can choose either of them according requirement. more info these 2 httpclient apis, please see demystifying httpclient apis in universal windows platform.
Comments
Post a Comment