public async Task<string> makeRequest() //1. Changed to async and return type { if (InternetAvailable()) { string strResponseValue = string.Empty; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint); request.Method = httpMethod.ToString(); request.ContentType = "application/json"; request.Accept = "application/json"; request.Headers.Add("Authorization", token); request.UserAgent = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"; if ((request.Method == "POST" || request.Method == "PUT") && postJSON != string.Empty) { using (StreamWriter swJSONPayload = new StreamWriter(await request.GetRequestStreamAsync())) //2. changed to asynchronous call { swJSONPayload.Write(postJSON); swJSONPayload.Close(); } } HttpWebResponse response = null; try { response =await (HttpWebResponse)request.GetResponseAsync(); //3. changed to asynchronous call // Process the response stream... (could be JSON, XML or HTML etc...) using (Stream responseStream =await response.GetResponseStreamAsync()) //4. changed to asynchronous call { if (responseStream != null) { using (StreamReader reader = new StreamReader(responseStream)) { strResponseValue = reader.ReadToEnd(); }// End of StreamReader } }// End of using ResponseStream } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; if (resp.StatusCode == HttpStatusCode.Unauthorized) { MessageBox.Show("Unauthorized", "Unauthorized", MessageBoxButtons.OK, MessageBoxIcon.Stop); Environment.Exit(1); } } } return strResponseValue; } else { return null; } }