如何在C#中将Salesforce与网站集成

时间:2017-10-03 06:54:40

标签: c# salesforce

我创建了一个.net Web应用程序来从Salesforce获取一些数据和元数据。因此,此应用程序首先要求salesforce用户名和密码登录,一旦登录成功,它将从salesforce获取一些数据。

我正在尝试下面的代码,这是对或错,请建议正确的方式

    string response_type = "code";
    string client_id = "...";
    string redirect_url = @"...";
    string client_secret = "....";

    // GET: LoginApp

    public void Login()
    {
         authorize();
    }


    public void authorize()
    {
        Redirect("");

        string URI = "";

        StringBuilder body = new StringBuilder();
        body.Append(URI);
        body.Append("?response_type=" + response_type + "&");
        body.Append("client_id=" + client_id + "&");
        body.Append("client_secret=" + client_secret + "&");
        body.Append("redirect_uri=" + redirect_url);
        //string red_url = body.ToString();
        string red_url = HttpPost(body.ToString());
        Response.Redirect(URI);
    }


    public string HttpPost(string URI)
    {
        WebRequest request = WebRequest.Create(URI);
        request.Method = "POST";
        string postData = "This is a test data.";
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = byteArray.Length;
        string res = request.RequestUri.ToString();
        Stream dataStream = request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();
        return res;
    }

0 个答案:

没有答案