我目前正在尝试写入BigCommerce oauth API,但我不断收到以下错误:
远程服务器返回错误:(400)错误的请求。
我想返回订单/客户/等的清单。任何建议,将不胜感激。
我的代码示例如下。
string baseURL = "https://api.bigcommerce.com/stores/" + storeHash + "/v2/" + resourcePath;
string contentType = "application/json";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseURL);
req.AllowAutoRedirect = true;
req.ContentType = contentType;
req.Method = "POST";
req.Headers.Add("X-Auth-Client", clientID);
req.Headers.Add("X-Auth-Token", token);
string sendRequest = "min_id=1";
byte[] postData = Encoding.UTF8.GetBytes(sendRequest);
req.ContentLength = postData.Length;
//Send the data to login server
using (Stream stream = req.GetRequestStream()) {
stream.Write(postData, 0, postData.Length);
stream.Flush();
stream.Close();
}
//Get the request response object
WebResponse resp = req.GetResponse();
//Read the contents of the response
StreamReader sr = new StreamReader(resp.GetResponseStream());
string jsonResponse = sr.ReadToEnd();
感谢您的评论,我得以提出以下解决方案:
//BigCommerce Authorization//
string clientID = "grmx4ghnscp8pz2jb4bf2qylt9b61yh";
string clientSecret = "ibjh6whikzab0jm84zgjw5uydstx1b8";
string token = "d56i5khv6l4kgcd9k92wpavyh93iqh";
string storeHash = "pdcnmnye";
string resourcePath = "products";
string baseURL = "https://api.bigcommerce.com/stores/" + storeHash + "/v2/" + resourcePath;
string requestParams = "?min_id=65&max_id=75";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseURL + requestParams);
req.AllowAutoRedirect = true;
req.ContentType = "application/json";
req.Accept = "application/json";
req.Method = "GET";
//string authValue = Convert.ToBase64String(Encoding.Default.GetBytes("admin:" + ""));
req.Headers.Add("X-Auth-Client", clientID);
req.Headers.Add("X-Auth-Token", token);
//req.Headers.Add("Authorization", authValue);
Trace.Write("Base URL",baseURL);
string jsonResponse = null;
using (WebResponse resp = req.GetResponse()) {
if (req.HaveResponse && resp != null) {
using (var reader = new StreamReader(resp.GetResponseStream())) {
jsonResponse = reader.ReadToEnd();
}
}
}
Response.Write(jsonResponse);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句