我的参数是这些:
string responseData = String.Empty;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://open.youzanyun.com/auth/token");
Encoding encoding = Encoding.UTF8;
IDictionary<string, string> para = new Dictionary<string, string>();
para.Add("authorize_type", "silent");
para.Add("client_id", "f34f8a76e25a8a5645");
para.Add("client_secret", "454a064ba886bfdabeb6cfe485df640c");
para.Add("grant_id", "129947060");
para.Add("refresh", "false");
StringBuilder buffer = new StringBuilder();
int i = 0;
foreach (string key in para.Keys)
{
if (i > 0)
{
buffer.AppendFormat("&{0}={1}", key, para[key]);
}
else
{
buffer.AppendFormat("{0}={1}", key, para[key]);
}
i++;
}
byte[] bs = Encoding.UTF8.GetBytes(buffer.ToString());
req.Method = "POST";
//req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
req.ContentType = "application/json";
req.ContentLength = bs.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(bs, 0, bs.Length);
reqStream.Close();
}
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
{
responseData = reader.ReadToEnd().ToString();
string shijian = DateTime.Now.ToString("yyyyMMdd");
}
}
return responseData;
|
|
用手机打开
收藏
赞 0
···
回复
|
|
|
|