这是我的 C# 代码。我正在尝试从我的调查猴子中为我的公司提取数据,拥有访问密钥和令牌。请我需要你的帮助/建议。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
namespace Servicetest
{
public class Program
{
public static void Main(string[] args)
{
const string urlAuth =
"http://api.surveymonkey.net/v2/surveys/get_response_counts?api_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
// const string contentType = "application/json";
const string contentType = "text/xml";
// System.Net.ServicePointManager.Expect100Continue = false;
try
{
var webRequest = WebRequest.Create(urlAuth) as HttpWebRequest;
const string token =
"XXXXXXXXXXXXXXXXXXXXXXXXXXXX=";
if (webRequest != null)
{
webRequest.Method = "POST";
webRequest.ContentType = contentType;
webRequest.Headers["Authorization"] = "bearer" + token;
var responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
if (responseReader != null)
{
string responseData = responseReader.ReadToEnd();
responseReader.Close();
webRequest.GetResponse().Close();
Console.Write(responseData);
}
}
}
catch (System.Net.WebException exc)
{
if ((exc.Response is System.Net.HttpWebResponse) &&
(exc.Response as System.Net.HttpWebResponse).StatusCode == System.Net.HttpStatusCode.Unauthorized)
Console.Write("401");
else
throw exc;
}
}
}