HttpWebResponse contentLength 总是 -1 [英] HttpWebResponse contentLength always -1

查看:47
本文介绍了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天全站免登陆