Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Session
- {
- private readonly static Lazy<Session> _instance = new Lazy<Session>(()=>new Session());
- public static Session Instance { get { return _instance.Value; } }
- private Session()
- {
- }
- public string Token { get; private set; }
- public void SetToken(string token)
- {
- Token = token;
- }
- }
- public class Test
- {
- public async Task<string> Post(string uri, string data)
- {
- var request = (HttpWebRequest)WebRequest.Create(uri);
- request.Method = "POST";
- request.ContentType = "application/json";
- var buffer = Encoding.UTF8.GetBytes(data);
- request.ContentLength = buffer.Length;
- var stream = await request.GetRequestStreamAsync();
- await stream.WriteAsync(buffer, 0, buffer.Length);
- stream.Close();
- var response = await request.GetResponseAsync();
- stream = response.GetResponseStream();
- if(stream == null)
- throw new ArgumentNullException();
- var reader = new StreamReader(stream);
- var result = await reader.ReadToEndAsync();
- reader.Close();
- stream.Close();
- response.Close();
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement