0

有一个代码可以在 geoserver 上创建新的 featureType:

string par = @"/c D:\curl-7.32.0-ssl-sspi-zlib-static-bin-w32\curl.exe -v -u admin:MYPASSWORD -XPOST -H ""Content-type: text/xml"" -d ""<featureType><name>" + name + @"</name><title>" + MyHtmlEncode(title) + @"</title></featureType>""  http://localhost:8080/geoserver/rest/workspaces/cite/datastores/postgis/featuretypes";
Process P = Process.Start(@"C:\Windows\System32\cmd.exe",par);

我想读取服务器的输出并处理错误,他们说我应该将 curl 替换为HttpClient,但我不知道如何描述授权 ( -u admin:MYPASSWORD)。

4

1 回答 1

0

它看起来像基本身份验证,所以应该这样做。

        var httpClient = new HttpClient();
        var authHeader = new AuthenticationHeaderValue("basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("admin:MYPASSWORD")));
        httpClient.DefaultRequestHeaders.Authorization = authHeader;

        var content = new StringContent("<featureType><name>" + name + @"</name><title>"  + MyHtmlEncode(title) + @"</title></featureType>" );
        content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
        var response = await httpClient.PostAsync("http://localhost:8080/geoserver/rest/workspaces/cite/datastores/postgis/featuretypes", content);
于 2013-10-26T17:07:31.940 回答