Created
July 8, 2020 08:39
-
-
Save umerfaruk/b6d76127e10b32daffd1003fcb2b1c71 to your computer and use it in GitHub Desktop.
HttpHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<string> GetTextBody(string url) | |
{ | |
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); | |
myRequest.Method = "GET"; | |
WebResponse myResponse = await myRequest.GetResponseAsync(); | |
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); | |
string result = await sr.ReadToEndAsync(); | |
sr.Close(); | |
myResponse.Close(); | |
return result; | |
} | |
public static async Task<Bitmap> GetImage(string imageUrl) | |
{ | |
var webRequest = (HttpWebRequest)WebRequest.Create(imageUrl); | |
webRequest.AllowWriteStreamBuffering = true; | |
webRequest.Timeout = 30000; | |
using (var webResponse = await webRequest.GetResponseAsync()) | |
{ | |
using (var stream = webResponse.GetResponseStream()) | |
{ | |
return new Bitmap(stream); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment