Search code examples
restasp.net-core-1.0geoserver

GeoServer returns 405: Method Not found during POST method


I am trying to implement Get,Post,Put and Delete operation on the layers using GeoServer Rest.

I am able to implement Get,Put and Delete method successfully.

But when i am trying to implement Post method on the layer, GeoServer returns status code: 405 i.e. Method Not Found.

Here is my code:

    public async Task<IActionResult> PostLayer(string layerName)
    {
        var authValue = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes("admin:geoserver")));
        try
        {
            var client = new HttpClient()
            {
                DefaultRequestHeaders = { Authorization = authValue }
            };
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.BaseAddress = new Uri("http://localhost:8080");
            var stringContent = new StringContent(@"C:\Users\i2vsys\Desktop\test.kml");

            var response = await client.PostAsync($"/geoserver/rest/layers/{layerName}",stringContent);
            response.EnsureSuccessStatusCode();
            var stringResponse = await response.Content.ReadAsStringAsync();
            return Ok(stringResponse);
        }
        catch (HttpRequestException ex)
        {
            return BadRequest(ex.Message);
        }
    }

But according to GeoServer api documentation it has POST method. So, problem is definitely from my side and i am unable to find that. I have also seen others question but those solution didn't work for me.

Any help would be appreciated.


Solution

  • When I look at the layers documentation I see no reference to POST requests. What did you hope that a POST would do?

    To create a new layer you first create a new DataStore as described in the examples. Using some thing like:

    curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip"
      --data-binary @roads.zip http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads/file.shp