public void GetValueFromRequest(string postData)
{
var request = (HttpWebRequest) WebRequest.CreateHttp("http://login.test.geoop.com/oauth2/token"); byte[] requestBytes =
Encoding.UTF8.GetBytes(
postData); request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = requestBytes.Length; request.BeginGetRequestStream(GetRequestStreamCallback, request);
} private static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
var request = (HttpWebRequest) asynchronousResult.AsyncState; // End the operation
var postStream = request.EndGetRequestStream(asynchronousResult); var postData = "grant_type=password&username=geooplive&password=geooppass&client_id=app4&scope=default"; // Convert the string into a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // Write to the request stream.
postStream.Write(byteArray, 0, postData.Length);
postStream.Close(); // Start the asynchronous operation to get the response
request.BeginGetResponse(GetResponseCallback, request);
} private static void GetResponseCallback(IAsyncResult asynchronousResult)
{
var request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response = null; // End the operation
try
{
response = (HttpWebResponse) request.EndGetResponse(asynchronousResult);
}
catch (WebException ex)
{
if (ex.Response != null)
{ }
} if (response.StatusCode == HttpStatusCode.Accepted)
{
Debug.WriteLine(response.ToString());
}
var streamResponse = response.GetResponseStream();
var streamRead = new StreamReader(streamResponse);
var responseString = streamRead.ReadToEnd();
Console.WriteLine(responseString);
// Close the stream object
streamResponse.Close();
streamRead.Close(); // Release the HttpWebResponse
response.Close();
}