[英]Simple API Post with HttpClient
I'm trying to get a balance from coinfloor using their API, while I was able to successfully parse their unauthenticated/public GET responses, I'm having troubles sending authenticated private POST requests with extra parameters. 我正在尝试使用他们的API来从coinfloor中获得一个平衡,尽管我能够成功解析他们的未认证/公共GET响应,但是在发送带有额外参数的已认证私人POST请求时遇到了麻烦。
Currently I get StatusCode: 401, ReasonPhrase: 'Unauthorized' 当前,我得到StatusCode:401,ReasonPhrase:“未经授权”
class Program
{
static HttpClient client = new HttpClient();
static void Main()
{
RunAsync().Wait();
}
static async Task RunAsync()
{
client.BaseAddress = new Uri("https://webapi.coinfloor.co.uk:8090/bist/XBT/GBP/balance/");
client.DefaultRequestHeaders.Authorization= new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "userID/apikey", "passphrase"))));
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("User ID","userid"),
new KeyValuePair<string, string>("API key","apikey"),
new KeyValuePair<string, string>("Passphrase","pass")
});
try
{
var result = await client.PostAsync("https://webapi.coinfloor.co.uk:8090/bist/XBT/GBP/balance/", content);
string resultContent = await result.Content.ReadAsStringAsync();
}
I've tried using both the default authorization headers and sending the data with FormUrlEncodedContent. 我尝试使用默认授权标头,并使用FormUrlEncodedContent发送数据。 their documentation says " All private API calls require authentication. You need to provide 3 parameters to authenticate a request: User ID, API key,Passphrase" 他们的文档说:“所有私有API调用都需要认证。您需要提供3个参数来认证请求:用户ID,API密钥,密码”
not sure what I'm doing wrong? 不知道我在做什么错?
and how should I be sending other extra parameters in the requests? 以及我应该如何在请求中发送其他额外的参数?
只是要指出代码实际上是正确的,我在使用各种ID和密码时就犯了一个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.