0

There is a code that creates new featureType at geoserver:

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);

I want to read output of server and handle errors, they said I should replace curl with HttpClient, but I don't know how to describe authorization (-u admin:MYPASSWORD).

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
Mike
  • 1

1 Answers1

0

It looks like basic auth, so this should do it.

        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);
Darrel Miller
  • 139,164
  • 32
  • 194
  • 243