阿里软件接口开发基础(淘宝网)附代码下载

主要开发文件见:

http://wiki.isv.alisoft.com/index.php?tracelog=doc_from_home

当前JAVA例子比较多,C#比较少,

下面提供本人开发一些例子:

向服务器发送请求类:

 public static XmlDocument HttpRequest(string data)
        {
            
//ASCIIEncoding encoding = new ASCIIEncoding();

            byte[] postdata = System.Text.Encoding.UTF8.GetBytes(data);//所有要传参数拼装
            
//
 Prepare web request
            
//目前阿里软件的服务集成平台(SIP)的接口测试地址是:http://sipdev.alisoft.com/sip/rest,生产环境地址是:http://sip.alisoft.com/sip/rest
,
            
//这里使用测试接口先,到正式上线时需要做切换

            string url = System.Configuration.ConfigurationManager.AppSettings["APPURL"];
            HttpWebRequest myRequest 
=
 (HttpWebRequest)WebRequest.Create(url);
            myRequest.Method 
= "POST"
;
            myRequest.ContentType 
= "application/x-www-form-urlencoded"
;
            myRequest.ContentLength 
=
 postdata.Length;
            Stream newStream 
=
 myRequest.GetRequestStream();
            
// Send the data.

            newStream.Write(postdata, 0, postdata.Length);
            newStream.Close();
            
// Get response

            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            StreamReader reader 
= new
 StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);

            XmlDocument xmlDoc 
= new
 XmlDocument();
            xmlDoc.LoadXml(reader.ReadToEnd());
            XmlNode node 
= xmlDoc.SelectSingleNode("/error_rsp/code"
);
            
if (node != null && node.InnerText != string
.Empty)
            {

                
throw new ApiException(node.InnerText, xmlDoc.SelectSingleNode("/error_rsp/msg"
).InnerText);
            }
            
return
 xmlDoc;

        }
        
public static string HttpRequest(string data, string
 xPath)
        {
            XmlDocument doc 
=
 HttpRequest(data);
            
return
 doc.SelectSingleNode(xPath).InnerText;
        }
        
public static string MD5(string
 data)
        {
            MD5CryptoServiceProvider md5 
= new
 MD5CryptoServiceProvider();
            
return BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(data))).Replace("-"""
);
        }

对参数进行排序类:

对参数时行排序

淘宝相关的一个操作类:

TAOBAO EXAMPLE
代码下载

posted on 2011-04-20 14:27  seoxs  阅读(562)  评论(0编辑  收藏  举报

导航