C# web request method with url and process the stream -
how use web request method?:
try { var request = webrequest.create(uri); using (var response = request.getresponse()) { using (var responsestream = response.getresponsestream()) { // process stream } } } catch (webexception ex) { if (ex.status == webexceptionstatus.protocolerror && ex.response != null) { var resp = (httpwebresponse)ex.response; if (resp.statuscode == httpstatuscode.notfound) { // } else { // else } } else { // else } } }
i found above code on website , i'm not sure process stream means or put url :ex: http://www.google.com prefer use code instead can't else statements work it, , need.
httpwebrequest request = (httpwebrequest)webrequest.create(string.format("url", hashe)); try { httpwebresponse response = (httpwebresponse)request.getresponse(); } catch (exception ex) { if (ex.tostring().contains("404")) { } }
you replace uri
address, or create string variable named uri , provide address.
eg.
string uri = "http://www.google.se"
but, better off using webclient.
webclient client = new webclient (); string reply = client.downloadstring ("http://www.google.se");
Comments
Post a Comment