简体   繁体   English

RestSharp到httpwebrequest的转换过程

[英]RestSharp to httpwebrequest converting process

I am trying to make a api call to " https://api.getresponse.com/v3 " with header "X-Auth-Token: api-key jfgs8jh4ksg93ban9Dfgh8" i already did it with RestSharp library bellow but somehow this not works. 我正在尝试通过标头“ X-Auth-Token:api-key jfgs8jh4ksg93ban9Dfgh8”对“ https://api.getresponse.com/v3 ”进行api调用,我已经在下面的RestSharp库中做到了,但是以某种方式无法正常工作。 So i want to try same thing with httpwebrequest. 所以我想用httpwebrequest尝试同样的事情。 Please provide an example same request using httpwebrequest i am new to c# that's why need help. 请使用httpwebrequest提供相同的请求示例,因为我是C#的新手,所以需要帮助。 Thanks in advance 提前致谢

 var client = new RestClient("https://api.getresponse.com/v3");
 var request = new RestRequest("/campaigns/", Method.POST);

 request.AddHeader("Content-Type", "application/json");
 request.AddHeader("X-Auth-Token:", "api-key 948dff91a017a07f3c6");
 request.Parameters.Clear();

 var response = client.Execute(request);

You say you want to send a header, but you do 您说要发送标题,但是您确实要发送

request.AddParameter("X-Auth-Token:", "api-key 948dff91a017a07f3c6");

Moreover you do Parameters.Clear after that. 此外,在此之后执行Parameters.Clear Maybe changing this to AddHeader will work? 也许将其更改为AddHeader可以工作吗?

Otherwise, please provide us with more details on what exactly does not work. 否则,请向我们提供更多有关无法正常工作的详细信息。

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

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