调查猴API获得远程服务器返回一个错误:403 forbidden和X-mashery错误代码:ERR_403_Serv

本文关键字:一个 forbidden 错误 X-mashery Serv ERR 错误代码 API 返回 服务器 调查 | 更新日期: 2023-09-27 17:50:41

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

}

调查猴API获得远程服务器返回一个错误:403 forbidden和X-mashery错误代码:ERR_403_Serv

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

相关文章: