Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. string code = HttpContext.Current.Request["code"];
  2.  
  3. // this is what we are sending
  4. string post_data = "client_id={0}&client_secret={1}&code={2}&redirect_uri={3}";
  5. post_data = string.Format(post_data, code, clientId, redirect_url, apiSecret);
  6. post_data = HttpUtility.UrlEncode(post_data);
  7.  
  8. // this is where we will send it
  9. string uri = "https://stackexchange.com/oauth/access_token";
  10.  
  11. // create a request
  12. HttpWebRequest request = (HttpWebRequest)
  13. WebRequest.Create(uri);
  14. request.KeepAlive = false;
  15. request.ProtocolVersion = HttpVersion.Version10;
  16. request.Method = "POST";
  17.  
  18. // turn our request string into a byte stream
  19. byte[] postBytes = Encoding.ASCII.GetBytes(post_data);
  20.  
  21. // this is important - make sure you specify type this way
  22. request.ContentType = "application/x-www-form-urlencoded";
  23. request.ContentLength = postBytes.Length;
  24. request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
  25. Stream requestStream = request.GetRequestStream();
  26.  
  27. // now send it
  28. requestStream.Write(postBytes, 0, postBytes.Length);
  29. requestStream.Close();
  30.  
  31. string post_data = "client_id={0}&client_secret={1}&code={2}&redirect_uri={3}";
  32. post_data = string.Format(post_data, code, clientId, redirect_url, apiSecret);
  33.  
  34. string post_data = "client_id={0}&client_secret={1}&code={2}&redirect_uri={3}";
  35. post_data = string.Format(post_data, clientId, apiSecret, code, redirect_url);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement