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



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

}

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

相关内容

最新更新