随笔 - 87  文章 - 1  评论 - 610  阅读 - 44万

阿里软件接口开发基础(淘宝网) C#

主要开发文件见:

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   edobnet  阅读(9220)  评论(8编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
< 2009年2月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
1 2 3 4 5 6 7
8 9 10 11 12 13 14

点击右上角即可分享
微信分享提示