我有 Rest API Url https://www.box.com/api/oauth2/token
。分别获取刷新/访问令牌。
PostMan (Chrome Extension)
当我在它工作正常时尝试这个。下面我附上了屏幕截图。
获取访问令牌参考:https ://developers.box.com/oauth/
但是我在 Code 中尝试过的同样是它给了我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);
}
我的问题是....
我需要如何形成这个休息的请求API call
?多表单数据和值如何需要合并到该请求?
通过邮递员请求邮箱:
我的代码中的框请求: