日期:2014-05-16  浏览次数:20531 次

速卖通的API调用,调试返回400错误,但谷歌浏览器却能看到Json数据

调试的时候返回
远程服务器返回错误: (400) 错误的请求。

在IE中无法打开,也是 远程服务器返回错误: (400) 错误的请求。

但是在谷歌浏览器中却能看到数据

地址
http://gw.api.alibaba.com/openapi/param2/1/aliexpress.open/api.findAeProductById/100000?productId=1&_aop_signature=DE1D9BDE00646F5C1704930003C9FC011AADDE25&access_token=HMKSwKPeSHB7Zk7712OfC2Gn1-kkfVsaM-P

代码如下

public static string GetPages()
        {
            string url = "http://gw.api.alibaba.com/openapi/param2/1/aliexpress.open/api.findAeProductById/100000?productId=1&_aop_signature=DE1D9BDE00646F5C1704930003C9FC011AADDE25&access_token=HMKSwKPeSHB7Zk7712OfC2Gn1-kkfVsaM-P";
            Encoding encoding = System.Text.Encoding.GetEncoding("utf-8"); //声明编码格式
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); //创建请求

            request.AllowAutoRedirect = true;
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader sr = new StreamReader(responseStream, encoding);
            string responseText = sr.ReadToEnd();
            sr.Close();
            sr.Dispose();
            responseStream.Close();
            string jsonData = responseText;
            return jsonData;

        }



这个url应该返回的是
{"error_code":"400","error_message":"com.alibaba.openapi.exception.request.RequestValidateException: Invalid appKey, unsport appKey: 100000","exception":"com.alibaba.openapi.exception.request.RequestValidateException: Invalid appKey, unsport appKey: 100000"}


是速卖通的API接口
------解决方案--------------------
遨游下也可以看到啊,这应该是IE的安全设置
------解决方案--------------------
不同浏览器对错误的处理方式不同

string url = "http://gw.api.alibaba.com/openapi/param2/1/aliexpress.open/api.findAeProductById/100000?productId=1&_aop_signature=DE1D9BDE00646F5C1704930003C9FC011AADDE25&access_token=HMKSwKPeSHB7Zk7712OfC2Gn1-kkfVsaM-P";
            Encoding encoding = System.Text.Encoding.GetEncoding("utf-8"); //声明编码格式
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); //创建请求