简体   繁体   English

将cUrl转换为restsharp

[英]Translate cUrl to restsharp

I have a cUrl request: 我有一个cUrl请求:

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# 我需要发出与上述类似的请求,但使用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;

instead of 代替

request.AddFile()

this worked for me: 这为我工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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