c# - Issue Connecting .NET Core with GridDB REST API - Stack Overflow

I am trying to connect my .NET Core service with GridDB using a REST API, but I am facing an issue whil

I am trying to connect my .NET Core service with GridDB using a REST API, but I am facing an issue while retrieving data.

Here's what I have done so far:

  1. Set Up GridDB Server.
  2. Installed and configured GridDB on my local machine.
  3. Verified that GridDB is running and accessible.
  4. Created a REST API Using Java (Spring Boot)

I built a simple REST API to expose GridDB data.

The API retrieves data from a specified container based on a given key.

Here's my API endpoint:

@RestController
@RequestMapping("/griddb")
public class GridDBController 
{
    private static final String GRIDDB_CLUSTER_NAME = "myCluster";
    private static final String GRIDDB_NOTIFICATION_MEMBER = "***.0.0.1";
    private static final String GRIDDB_USERNAME = "***";
    private static final String GRIDDB_PASSWORD = "****";

    @GetMapping("/get/{container}/{key}")
    public ResponseEntity<String> getData(@PathVariable String container, @PathVariable String key) 
    {
        try 
        {
            GridStore store = GridStoreFactory.getInstance().getGridStore(
                new Properties() {{
                    setProperty("notificationMember", GRIDDB_NOTIFICATION_MEMBER);
                    setProperty("clusterName", GRIDDB_CLUSTER_NAME);
                    setProperty("user", GRIDDB_USERNAME);
                    setProperty("password", GRIDDB_PASSWORD);
                }});

            Container<String, Row> col = store.getContainer(container);
            Row row = col.get(key);

            return ResponseEntity.ok(row.toString());
        } 
        catch (Exception e) 
        {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error: " + e.getMessage());
        }
    }
}

This works fine when tested with Postman (returns expected data).

Consuming the REST API in .NET Core: I am trying to call this API from my .NET Core service using HttpClient:

using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        string baseUrl = "http://localhost:8080/griddb";  // Java API URL
        string container = "sensorData";
        string key = "device***";

        using HttpClient client = new HttpClient();
        HttpResponseMessage response = await client.GetAsync($"{baseUrl}/get/{container}/{key}");

        if (response.IsSuccessStatusCode)
        {
            string data = await response.Content.ReadAsStringAsync();
            Console.WriteLine("Received Data: " + data);
        }
        else
        {
            Console.WriteLine("Failed to retrieve data. Status: " + response.StatusCode);
        }
    }
}

Issues I am facing:

  • When I call the API using Postman, it returns data correctly
  • But when I call it from .NET Core using HttpClient, I get (mention actual error message here, like timeout, 404, 500, etc.)
  • I have checked the API URL and it is correct

What I have tried:

  • Tested with Postman → works fine.
  • Tried HttpClient with different headers and settings
  • Checked if the Java API is running and accessible from a browser
  • Tried increasing timeout settings

Questions

  • What could be the reason my .NET Core service is unable to get a response from the GridDB REST API, even though Postman works?
  • Do I need to handle any specific CORS, firewall, or networking issues?
  • Is there a better way to connect .NET Core with GridDB?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744333778a4569013.html

相关推荐

  • c# - Issue Connecting .NET Core with GridDB REST API - Stack Overflow

    I am trying to connect my .NET Core service with GridDB using a REST API, but I am facing an issue whil

    7天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信