HttpWebResponse contentLength始终为-1 [英] HttpWebResponse contentLength always -1

查看:887
本文介绍了HttpWebResponse contentLength始终为-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络请求后,我的网络响应内容长度似乎总是为-1.我确定您按摩和签名正确. 我在这里做什么错了?

My web response content length always seem to be -1 after my web request. I'm sure you massage and signature are right. What am I doing wrong here?

            string msg = string.Format("{0}{1}{2}", nonce, clientId, apiKey);
            string signature = ByteArrayToString(SignHMACSHA256(apiSecret, StrinToByteArray(msg))).ToUpper();
            const string endpoint = "https://www.bitstamp.net/api/balance/";
            HttpWebRequest request = WebRequest.Create(endpoint) as HttpWebRequest;
            request.Proxy = null;
            request.Method = "POST";
            request.ContentType = "application/xml";
            request.Accept = "application/xml";
            request.Headers.Add("key", apiKey);
            request.Headers.Add("signature", signature);
            request.Headers.Add("nonce", nonce.ToString());
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

推荐答案

使其与webClient(而不是httpWebRequest)一起使用. 如果有人可以将其与httpWebRequest一起使用,您将得到答案.

Got it working with webClient instead of the httpWebRequest. If someone can get it working with httpWebRequest, you wil get the answer.

            string msg = string.Format("{0}{1}{2}", nonce, clientId, apiKey);
            var signature = ByteArrayToString(SignHMACSHA256(apiSecret, StrinToByteArray(msg))).ToUpper();
            var path = "https://www.bitstamp.net/api/user_transactions/";

            using (WebClient client = new WebClient())
            {

                byte[] response = client.UploadValues(path, new NameValueCollection()
                {
                    { "key", apiKey },
                    { "signature", signature },
                    { "nonce", nonce.ToString()},

                });

                var str = System.Text.Encoding.Default.GetString(response);
            }

这篇关于HttpWebResponse contentLength始终为-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆