在C#中将Raw XML发送到Tableau Rest API的正确方法

时间:2016-10-26 00:56:04

标签: c# xml rest tableau

我只是想向Tableau的REST API发送一个休息请求,但出于某种原因,.NET并不发送原始XML(虽然已经过测试,但它使用的是Postman in chrome)

var admin = "\hardcoded_admin_user"\"";
var pass = "\hardcoded_pass"\"";

var tableau_signin = String.Format("<tsRequest> <credentials name={0} password={1}> </credentials> <site contentUrl=\"\"/> </tsRequest>", admin, pass);
    //if user is validated make a REST call to Tableau Server
    string endPoint = @"http://server/api/2.0/auth/signin";

    HttpClient client = new HttpClient();
    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
    var post = client.PostAsync(endPoint,
           new StringContent(tableau_signin)).Result;
    }

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:0)

在StringContent中提供编码和内容类型。

var post = client.PostAsync(endPoint,
           new StringContent(tableau_signin, Encoding.UTF8, "application/xml")).Result;

答案 1 :(得分:0)

public class MainWindowViewModel : INotifyPropertyChanged
{
    private bool vButton;
    public event PropertyChangedEventHandler PropertyChanged;
    public bool VButton
    {
        get
        {
            return vButton;
        }
        set
        {
            if (value != vButton)
            {
                this.vButton = value;
                NotifyPropertyChanged("VButton");
            }
        }
    }

    private void NotifyPropertyChanged(String propertyName = "")
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}