我一直在尝试按照Dev Power BI说明从我的Consol应用程序创建一个Datatset但是继续得到以下例外:
"在调用[Begin] GetResponse"之前,您必须为请求流编写ContentLength字节。 贝娄是书面代码。
private static void CreateDataset()
{
string PowerBIDatasetsApiUrl = "https://api.powerbi.com/v1.0/myorg/datasets";
HttpWebRequest request = System.Net.WebRequest.Create(PowerBIDatasetsApiUrl) as System.Net.HttpWebRequest;
request.KeepAlive = true;
request.Method = "POST";
request.ContentLength = 0;
request.ContentType = "application/json";
request.Headers.Add("Autorization", String.Format("Bearer {0}", token));
string datasetJson = "{\"name\": \"SalesMarketing\", \"tables\": " +
"[{\"name\": \"product\", \"columsa\":" +
"[{\"name\": \"productID\", \"dataType\": \"Int64\"}, " +
"[{\"name\": \"category\", \"dataType\": \"string\"}, " +
"[{\"name\": \"IsCompete\", \"dataType\": \"bool\"}, " +
"[{\"name\": \"ManufacturedOn\", \"dataType\": \"DateTime\"}" +
"]}]}";
byte[] byteAray = System.Text.Encoding.UTF8.GetBytes(datasetJson);
request.ContentLength = byteAray.Length;
using (Stream writer = request.GetRequestStream())
{
writer.Write(byteAray, 0, byteAray.Length);
var response = (HttpWebResponse)request.GetResponse();
Console.WriteLine(string.Format("Dataset {0}", response.StatusCode.ToString()));
Console.ReadLine();
}
}