Translate cUrl to restsharp

江枫思渺然 提交于 2019-12-12 03:32:31

问题


I have a cUrl request:

curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary @C:\nyc_khr.zip  http://localhost:9090/geoserver/rest/workspaces/nyc_roads/datastores/roads/file.shp

I need make a request like above, but using C#
Example of my code:

RestClient client = new RestClient(URL)
{
      Authenticator = new HttpBasicAuthenticator("admin", "geoserver")
};

var data = File.ReadAllBytes(somePath);


string url = @"rest/workspaces/nyc_roads/datastores/roads/finalas.shx";
var request = new RestRequest(url, Method.PUT);
request.AddHeader("Content-Type", "application/zip");

request.AddFile("finalik.zip", data, "finalik.zip", "application/zip");
var response = client.Execute(request);
var res = response.ContentType;

回答1:


instead of

request.AddFile()

this worked for me:

request.Parameters.Clear();
request.AddParameter("application/zip", data, ParameterType.RequestBody);


来源:https://stackoverflow.com/questions/35150097/translate-curl-to-restsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!