简体   繁体   中英

Geoserver returns 405:Method Not Allowed

I am attempting to create a Geoserver REST client in C#. Example code below:

private static string GEOSERVER_HOST = "http://10.0.0.248:8080/geoserver/rest/";
private static string GEOSERVER_USER = "admin";
private static string GEOSERVER_PASSWD = "geoserver";

public WebResponse PerformRequest(string endPoint, string requestBody, string method = "PUT")
{
    string gUrl = GEOSERVER_HOST + endPoint;
    WebRequest request = WebRequest.Create(gUrl);

    request.ContentType = "text/xml";
    request.Method = method;
    request.Credentials = new NetworkCredential(GEOSERVER_USER, GEOSERVER_PASSWD);

    if (method != "GET")
    {
        byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(requestBody);
        Stream requestStream = request.GetRequestStream();
        requestStream.Write(buffer, 0, buffer.Length);
        requestStream.Close();
    }
    WebResponse response = request.GetResponse();

    return response;
}

public bool AddNewWorkspace(string workspaceName)
{
    try
    {
        PerformRequest("workspaces", "<workspace><name>"+ workspaceName+"</name></workspace>");
        return true;
    }
    catch (Exception ex)
    {
        return false;
    }
}

When executing request.GetResponse(), an exception is returned "405:Method Not Allowed".

I am using a fairly recent Geoserver (I believe it's 2.8.something). Default installation options selected. REST capabilities are turned on (I can browse the /rest/ "directory" using a browser.

Geoserver is running on a 32 bit Windows 8 machine. And Geoserver is started.

I can also perform GET requests without problem, so authentication seems to be working.

Any help would be appreciated.

HTTP/1.1 405 Method Not Allowed typically refers to the request method/verb.

Your parameter method has a default value of "PUT" which you're not overriding when calling PerformRequest .

It would seem that /geoserver/rest/workspaces does not support the PUT operation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM