如何使用Amazon的AWS的中国地区的API,即CN版本的AWS的API

2025-02-24 19:21:15
推荐回答(1个)
回答1:

1.参考:
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/CHAP_WhatsNew.html
得知,当前用的,虽然不是最新的2011-08-02:
【记录】寻找AWSECommerceService的最新版本
但是,是比较新的,2011-08-01,其已经如上所述:

New Marketplace
The IT (Italy) and CN (China) marketplaces were added.
1 August 2011

即,已经支持CN了。
2.用了默认的US的.com:
private static void cn_browseNodeLookupTest()
{
string _awsApiVersion = "2011-08-01";
string _awsDestination_cn = "ecs.amazonaws.com";

SignedRequestHelper helper_cn = new SignedRequestHelper(
awsAccessKeyId,
awsSecretKey,
awsAssociateTag,
_awsDestination_cn);

/*
* Here is an ItemLookup example where the request is stored as a dictionary.
*/
IDictionary reqDict = new Dictionary();
reqDict["Service"] = "AWSECommerceService";
reqDict["Version"] = _awsApiVersion;
reqDict["Operation"] = "BrowseNodeLookup";

//http://docs.aws.amazon.com/AWSECommerceService/latest/DG/BrowseNodeIDs.html
//for CN: Appliances -> 80207071
reqDict["BrowseNodeId"] = "80207071";

reqDict["ResponseGroup"] = "BrowseNodeInfo";

/*
* The helper supports two forms of requests - dictionary form and query string form.
*/
String requestUrl;

requestUrl = helper_cn.Sign(reqDict);

//WebRequest request = HttpWebRequest.Create(requestUrl);
//WebResponse response = request.GetResponse();
//XmlDocument doc = new XmlDocument();
//doc.Load(response.GetResponseStream());

XmlDocument xmlDoc = new XmlDocument();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUrl);
req.Method = "GET";
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr;
string charset = "UTF-8";
Encoding htmlEncoding = Encoding.GetEncoding(charset);
sr = new StreamReader(resp.GetResponseStream(), htmlEncoding);
string respHtml = sr.ReadToEnd();
sr.Close();
resp.Close();
xmlDoc.LoadXml(respHtml);

System.Console.WriteLine(xmlDoc.InnerXml);
}

返回xml是:


c7fada9f-13da-4312-bcfb-10c16eb3d035











0.011964



True

80207071
BrowseNodeInfo



AWS.InvalidParameterValue
80207071 is not a valid value for BrowseNodeId. Please change this value and retry your request.






即,和预期的一样,是无效的id。

3.又去试了试,用.cn的:
private static void cn_browseNodeLookupTest()
{
string _awsApiVersion = "2011-08-01";
string _awsDestination_cn = "ecs.amazonaws.cn";

SignedRequestHelper helper_cn = new SignedRequestHelper(
awsAccessKeyId,
awsSecretKey,
awsAssociateTag,
_awsDestination_cn);

/*
* Here is an ItemLookup example where the request is stored as a dictionary.
*/
IDictionary reqDict = new Dictionary();
reqDict["Service"] = "AWSECommerceService";
reqDict["Version"] = _awsApiVersion;
reqDict["Operation"] = "BrowseNodeLookup";

//http://docs.aws.amazon.com/AWSECommerceService/latest/DG/BrowseNodeIDs.html
//for CN: Appliance