起始页面为Login.aspx,固定调试端口为49441。需要配合自己淘宝开放平台的应用的回调页面URL来调整。
ashx代码:
(说明:代码中ITopClient为淘宝接口TopSdk.dll中的类,此例子使用的ItemsOnsaleGetRequest是用于获取销售中的商品,response.Body是获取到的数据信息)
复制代码代码如下:
public class OnsaleGet : IHttpHandler
{</p><p> public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
ITopClient client = new DefaultTopClient(Config.ServerURL, Config.Appkey, Config.Secret);</p><p> ItemsOnsaleGetRequest req = new ItemsOnsaleGetRequest();
req.Fields = "approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id";
ItemsOnsaleGetResponse response = client.Execute(req, Config.Top_session);</p><p>
if (response.IsError)
{
context.Response.Write("[错误:查询函数执行失败]");
}
else
{
context.Response.Write(response.Body);
}</p><p> }</p><p> public bool IsReusable
{
get
{
return false;
}
}
}
前端SL获取数据信息的方法
复制代码代码如下:
void GetList()
{
string absolutePath = HtmlPage.Document.DocumentUri.AbsoluteUri;
string address = absolutePath.Substring(0, absolutePath.LastIndexOf('/'))
+ "/TaoBaoHandler/OnsaleGet.ashx";</p><p> Uri uri = new Uri(address);</p><p> WebClient client = new WebClient();
client.DownloadStringCompleted += (sender, e) =>
{
if (e.Error == null)
{
System.Xml.Linq.XElement.Parse(e.Result);//字符串转为xml
ItemsOnsaleGetResponse list = SerializeHelper.DeserializeFromString<ItemsOnsaleGetResponse>(e.Result);//反序列化
if (list != null)
{
if (list.Items != null && list.Items.Count > 0)
{
MessageBox.Show(list.Items[0].NumIid.ToString());
}
}
else
{
}
}
else
{
MessageBox.Show(e.Error.Message);
新闻热点
疑难解答