如何从C#

时间:2016-10-19 16:19:59

标签: c# post webclient mixpanel

我对C#的Web访问很新,而且对Mixpanel来说是全新的。我正在尝试使用以下代码运行查询:

using (WebClient wc = new WebClient())
{
  wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
  byte[] creds = UTF8Encoding.UTF8.GetBytes("<my API secret>:");
  wc.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(creds));
  var reqparm = new System.Collections.Specialized.NameValueCollection();
  reqparm.Add("script", "function main() { return Events({\"from_date\":\"2016-10-01\",\"to_date\":\"2016-10-167\"}).reduce(mixpanel.reducer.count()); }");
  byte[] responsebytes = wc.UploadValues("https://mixpanel.com/api/2.0/jql", "POST", reqparm);
}

查询直接来自此Mixpanel示例:

function main()
{
  return Events
  ({
    from_date: "2016-01-04",
    to_date: "2016-01-04"
  }).reduce(mixpanel.reducer.count());
}

我在上面尝试过很多变化,但UploadValues总是返回400(错误请求)。我做错了什么?

TIA

1 个答案:

答案 0 :(得分:0)

我没有注意到的其中一个日期出现错误(“2016-10-167”)。