无法预览Geoserver中通过REST上传的shapefile

时间:2016-06-02 14:09:03

标签: c# esri geoserver

我已经设法通过REST API使用有用的在线cURL示例获取我的shapefile存档以发布到Geoserver。虽然我不得不将它们翻译成C#和HttpWebRequest类。现在,一切正常,因为我可以上传文件,然后在预览格式下拉列表中的WFS选项下以任何格式请求它:

enter image description here

enter image description here

但是,我无法在OpenLayers中预览它或请求任何WMS格式(栅格等)。请注意请求URL中的null,我认为这是问题,但它可能是更大问题的症状。

enter image description here

enter image description here

现在,我的上传代码运行正常,但在这里,以防你想知道。或许我需要再打一次电话。

旁注:是的,我知道我基本上复制了身份验证,但WebRequest发送了一个未经身份验证的第一个请求,这是解决这个问题的唯一方法。:< / p>

public bool UploadShapeFile(string workspace, string newStoreName, byte[] fileContents)
    {

        byte[] localShapeFile = fileContents;

        String sUrl = GEOSERVER_HOST + "rest/workspaces/" + workspace + "/datastores/" + newStoreName + "/file.shp";
        WebRequest request = WebRequest.Create(sUrl);

        request.ContentType = "application/zip";
        request.Method = "PUT";
        request.Credentials = new NetworkCredential(GEOSERVER_USER, GEOSERVER_PASSWD);

        request.Headers.Add("Authorization", "Basic " +
                                                Convert.ToBase64String(
                                                Encoding.ASCII.GetBytes(GEOSERVER_USER + ":" + GEOSERVER_PASSWD)));

        // byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(@fileUri);
        Stream requestStream = request.GetRequestStream();
        requestStream.Write(localShapeFile, 0, localShapeFile.Length);
        requestStream.Close();

        WebResponse response = request.GetResponse();


        return false;

    }

0 个答案:

没有答案
相关问题