これが私の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;
}
}
}