0

这是我的 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;
        }

    }


}
4

1 回答 1

1

端点需要 SSL,只需将您的 url 从 http:// 更改为 https://,即https://api.surveymonkey.net/v2/surveys/get_response_counts?api_key=xxxxxxxxx

于 2014-03-17T16:58:34.983 回答