将cUrl转换为restsharp [英] Translate cUrl to restsharp

查看:200
本文介绍了将cUrl转换为restsharp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个URL请求:

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

我需要像上面那样发出请求,但是使用C#

我的代码示例:

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;


推荐答案

而不是

request.AddFile()

此为我工作:

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

这篇关于将cUrl转换为restsharp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆