首页 > 解决方案 > 通过c#将数据推送到gmail Streak

问题描述

我正在尝试通过 c# 中的 API 将数据推送到 gmail streak,基本上我正在尝试通过 API 创建管道,但它给出了 400 Bad Request 错误但我正在根据其网站链接中给出的所有数据传递所有数据:- https ://streak.readme.io/reference#create-a-pipeline

代码 -

try
     {


            CookieContainer myContainerpush = new CookieContainer();
            HttpWebRequest requestpush = (HttpWebRequest)WebRequest.Create("https://www.streak.com/api/v1/pipelines/");
            requestpush.Method = "POST";
            requestpush.Credentials = new NetworkCredential("gh0b9shff5f77e310cea", "");

            String encodedAllPipelines = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes("ee3deb0b9f7c4d6c92f5f5f77e310cea:"));
            requestpush.Headers.Add("Authorization", "Basic " + encodedAllPipelines);

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            // allows for validation of SSL conversations
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            requestpush.CookieContainer = myContainerpush;
            requestpush.PreAuthenticate = true;

            string postData = "{ name:'Hiring', teamWide: false,fieldNames: ['Test'],fieldTypes: ['TEXT_INPUT'],stageNames: ['SNOw'],teamkey: 'agxdsfsdfsdf9nYWVyEQsSBFRlYW0YgICI_fG-9QsM'}";

             byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            // Set the ContentType property of the WebRequest.  
            requestpush.ContentType = "application/x-www-form-urlencoded";
            requestpush.ContentLength = byteArray.Length;

            //// Get the request stream.  
            Stream dataStream = requestpush.GetRequestStream();
            //// Write the data to the request stream.  
            dataStream.Write(byteArray, 0, byteArray.Length);
            //// Close the Stream object.  
            dataStream.Close();

            // Get the response.  
            WebResponse response = requestpush.GetResponse();
            // Display the status.  
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);

            // Get the stream containing content returned by the server.  
            // The using block ensures the stream is automatically closed.
            using (dataStream = response.GetResponseStream())
            {
                // Open the stream using a StreamReader for easy access.  
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.  
                string responseFromServer = reader.ReadToEnd();
                // Display the content.  
                Console.WriteLine(responseFromServer);
            }

            // Close the response.  
            response.Close();

        }
        catch (Exception e)
         {
            e.Message.ToString();
         }

标签: c#asp.netapiasp.net-web-apigmail

解决方案


推荐阅读