| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System;
- using System.IO;
- using System.Net;
- namespace Muchinfo.MTPClient.Infrastructure.Utilities
- {
- public enum RequestMethod
- {
- Get, Post
- }
- public class HttpUtility
- {
- public static string HttpGet(string url)
- {
- var request = CreateGetRequest(url);
- try
- {
- var response = (HttpWebResponse)request.GetResponse();
- var stream = response.GetResponseStream();
- if (stream == null) return string.Empty;
- var streamReader = new StreamReader(stream);
- string responseContent = streamReader.ReadToEnd();
- response.Close();
- streamReader.Close();
- return responseContent;
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- return null;
- }
- }
- private static HttpWebRequest CreateGetRequest(string url)
- {
- url = url.Trim();
- if (!url.Contains("://"))
- url = "http://" + url;
- var request = (HttpWebRequest)WebRequest.Create(url);
- request.ContentType = "application/json";
- request.Method = "GET";
- request.Timeout = 20000;
- return request;
- }
- }
- }
|