请教:stream load导入数据报权限错误
hanliang421 发布于2021-09 浏览:1871 回复:3
0
收藏

请教:通过httpclient方式向doris导入数据出错“no valid Basic authorization”。username使用doris的root账号,password确认密码没错。现象是:url如果是FE的地址则会报错,而改成BE的地址则没有问题。核心代码如下:

url = $"{url}{Dbname}/{Table}/_stream_load";

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

HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

request.Method = "PUT";

request.KeepAlive = true;

request.AllowAutoRedirect = true;

request.ContentType = "application/json;charset=UTF-8";

request.UserAgent = "Mozilla/4.0 (compatible;MSIE 6.0;)";

request.ContentLength = postData.Length;

request.Timeout = 60000;

request.Headers.Add("expect", "100-continue");

request.Headers.Add("format", "json");

request.Headers.Add("strip_outer_array", "true");

request.Headers.Add("jsonpaths", jsonpaths);

request.Headers.Add("label", DealLabe);

request.PreAuthenticate = true;

string usernamePassword = username + ":" + password;

CredentialCache mycache = new CredentialCache();

mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));

request.Credentials = mycache;

request.Headers.Add("Authorization", "Basic " + (Convert.ToBase64String(Encoding.UTF8.GetBytes(usernamePassword))).Cof_FilterUnVisible());

 

// 提交请求数据

System.IO.Stream outputStream = request.GetRequestStream();

outputStream.Write(postData, 0, postData.Length);

outputStream.Close();

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

Stream responseStream = response.GetResponseStream();

StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.GetEncoding("UTF-8"));

ResultStr = reader.ReadToEnd();

reader.Close();

收藏
点赞
0
个赞
共3条回复 最后由hanliang421回复于2021-09
#4hanliang421回复于2021-09
#2 IamStrangers回复
可能是没有正确的处理307转发问题

请问能再详细指点一下该如何解决吗?这个问题困扰好久了,感谢~

doris be信息如下:

0
#3hanliang421回复于2021-09

请问能再详细指点一下该如何解决吗?这个问题困扰好久了,感谢~

doris be信息如下:

0
#2IamStrangers回复于2021-09

可能是没有正确的处理307转发问题

0
快速回复
TOP
切换版块