这是我的代码
string URL = "https://api.fastspring.com/accounts";
using (var wb = new WebClient())
{
var data = new NameValueCollection();
var contact = new NameValueCollection();
data["contact"] = "first="+FirstName+"&last="+LastName+"&email="+Email+"&company="+Company;
data["language"] = Language;
data["country"] = Country;
var headers = new WebHeaderCollection();
headers["Authorization"] = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes("username:password"));
headers["User-Agent"] = "request";
//headers["Content-Type"] = "application/json";
wb.Headers = headers;
var response = wb.UploadValues(URL, "POST", data);
return (System.Text.Encoding.UTF8.GetString(response)).Split('"')[3];
}
我的问题是我继续收到401错误说未经授权。首先,我的身份验证语法是否正确?我的整个设置是否正确地向服务器发送HTTP请求?
这里有一些关于fastspring api的有用资源,如果有帮助的话:
http://docs.fastspring.com/integrating-with-fastspring/fastspring-api