I have the Rest API Url https://www.box.com/api/oauth2/token
. To get the Refresh/Access Tokens respectively.
When i try this in PostMan (Chrome Extension)
Its working fine. Below i have attached the screen shot.
Getting the Access Token Reference : https://developers.box.com/oauth/
But the same i tried in Code its giving me the Bad Request Error
.
public string PostToUrl(string url, string data)
{
string results = String.Empty;
WebRequest req = WebRequest.Create(url);
req.Method = WebRequestMethods.Http.Post;
byte[] byteArray = Encoding.UTF8.GetBytes(data);
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = byteArray.Length;
Stream dataStream = req.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse res = req.GetResponse();
dataStream = res.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
results = reader.ReadToEnd();
return results;
}
public override void TestConnection(TimeSpan timeout)
{
string json = PostToUrl("https://www.box.com/api/oauth2/token", "code=" + Code + "&grant_type=authorization_code&client_id=" + ClientId + "&client_secret=" + ClientSecret);
}
here my question is....
How do i need to form the request for this rest API call
?
How the Multi Form Data's and values need to be merged to that request?
Box Request through Post Man:
Box Request from My Code :