Home > Back-end >  Hbase rest API of adding new data in table dont work
Hbase rest API of adding new data in table dont work

Time:11-26

Truying to put some data inside the table (table is already exist) here is code (C#):

async Task AddData(HttpClient httpClient, string tableName, string columnName, string columnFamilyName, string key, string data)
{
    using (var request = new HttpRequestMessage(new HttpMethod("PUT"), $"http://localhost:8080/{tableName}/{key}"))
    {
        request.Headers.TryAddWithoutValidation("Accept", "application/json");

        var keyInBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(key));
        var columnInBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(columnName));
        var dataInBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(data));
        var columnFamilInBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(columnFamilyName));
        var FamilyAndColumnInBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(columnFamilyName   ":"   columnName));

        request.Content = new StringContent($"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CellSet><Row key=\"{keyInBase64}=\"><Cell column=\"{FamilyAndColumnInBase64}=\">{dataInBase64}==</Cell></Row></CellSet>");
        request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("text/xml");

        var response = await httpClient.SendAsync(request);

        Console.WriteLine(response);
        Console.WriteLine(await response.Content.ReadAsStringAsync());
    }
}


using (var httpClient = new HttpClient())
{
    await AddData(httpClient, "players", "nicknames", "playerData", "somekey", "CoolGuy");
}

And here is what i got:

I already search thru google and saw a lot of github repositories but didn't find an answer. Request of creating table and deleting it works fine.

Any ideas? Is my request correct? Thanks.

CodePudding user response:

<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CellSet><Row key=\"{keyInBase64}=\"><Cell column=\"{FamilyAndColumnInBase64}=\">{dataInBase64}==</Cell></Row></CellSet>

need to be

<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CellSet><Row key=\"{keyInBase64}\"><Cell column=\"{FamilyAndColumnInBase64}=\">{dataInBase64}</Cell></Row></CellSet>

I miss to delete "="....

  • Related