C# 如何在c中连接amazonapi#
我尝试使用以下内容连接Amazon API,但未能连接。我收到错误,因为“远程服务器返回错误:(400)错误请求”。如何解决这个问题。任何帮助都将不胜感激 代码:C# 如何在c中连接amazonapi#,c#,asp.net,amazon-web-services,amazon-s3,amazon,C#,Asp.net,Amazon Web Services,Amazon S3,Amazon,我尝试使用以下内容连接Amazon API,但未能连接。我收到错误,因为“远程服务器返回错误:(400)错误请求”。如何解决这个问题。任何帮助都将不胜感激 代码: protected void btnAmazonItemSerach_Click(object sender, EventArgs e) { string associateId = "**************"; string accessKey = "*************"; string sec
protected void btnAmazonItemSerach_Click(object sender, EventArgs e)
{
string associateId = "**************";
string accessKey = "*************";
string secretKey = "**************************";
string url = "http://webservices.amazon.com/onca/xml";
HttpWebRequest oRequest = (HttpWebRequest)HttpWebRequest.Create(url);
oRequest.Method = "GET";
oRequest.ContentType = "application/xml";
oRequest.Headers.Add("AWSAccessKeyId", accessKey);
oRequest.Headers.Add("AssociateTag", associateId);
oRequest.Headers.Add("Keywords", "Blueant s4");
oRequest.Headers.Add("Operation", "ItemSearch");
oRequest.Headers.Add("Service", "AWSECommerceService");
Encoding oEncod = new UTF8Encoding();
HMACSHA1 signature = new HMACSHA1();
signature.Key = oEncod.GetBytes(secretKey);
string sign = Convert.ToBase64String(signature.Key);
oRequest.Headers.Add("Signature", sign);
oRequest.Headers.Add("SearchIndex", "All");
oRequest.Headers.Add("Version", "2011-08-01");
string dateval = DateTime.Now.ToString();
oRequest.Headers.Add("Timestamp", dateval);
HttpWebResponse oResponse =(HttpWebResponse) oRequest.GetResponse();
StreamReader oreader =new StreamReader(oResponse.GetResponseStream());
var val = oreader.ReadToEnd();
XmlDocument oxmldoc = new XmlDocument();
oxmldoc.LoadXml(val);
XmlElement oxmlelem = (XmlElement)oxmldoc.GetElementsByTagName("Items")[0];
if (oxmlelem != null)
{
List<string> olistItems = new List<string>();
XmlNodeList olist = oxmldoc.GetElementsByTagName("Item");
for (int i = 0; i < olist.Count; i++)
{
string asi = olist[i].FirstChild.InnerText;
olistItems.Add(asi);
}
}
}
protectedvoid btnAmazonItemSerach\u单击(对象发送方,事件参数e)
{
字符串associateId=“****************”;
字符串accessKey=“*************”;
字符串secretKey=“****************************”;
字符串url=”http://webservices.amazon.com/onca/xml";
HttpWebRequest oRequest=(HttpWebRequest)HttpWebRequest.Create(url);
oRequest.Method=“GET”;
oRequest.ContentType=“应用程序/xml”;
添加(“AWSAccessKeyId”,accessKey);
添加(“AssociateTag”,associateId);
添加(“关键词”,“蓝蚂蚁s4”);
添加(“操作”、“项目搜索”);
oRequest.Headers.Add(“服务”、“AWSECommerceService”);
Encoding oEncod=新的UTF8Encoding();
HMACSHA1签名=新的HMACSHA1();
signature.Key=oEncod.GetBytes(secretKey);
string sign=Convert.ToBase64String(signature.Key);
添加(“签名”,签名);
添加(“SearchIndex”、“All”);
oRequest.Header.Add(“版本”,“2011-08-01”);
字符串dateval=DateTime.Now.ToString();
添加(“时间戳”,dateval);
HttpWebResponse OrResponse=(HttpWebResponse)oRequest.GetResponse();
StreamReader或Reader=新的StreamReader(orResponse.GetResponseStream());
var val=oreader.ReadToEnd();
XmlDocument oxmldoc=新的XmlDocument();
LoadXml(val);
xmlement-oxmlelem=(xmlement)oxmldoc.GetElementsByTagName(“项”)[0];
if(oxmlelem!=null)
{
List olistItems=新列表();
XmlNodeList olist=oxmldoc.GetElementsByTagName(“项目”);
for(int i=0;i