用于POST的restsharp AddParameter无法在Mac上运行(单声道)

时间:2014-01-29 18:23:53

标签: macos mono restsharp

在Xamarin 4.2.2上使用RestSharp 104.4.0。

我无法弄清楚为什么RestSharp不会将参数添加到POST请求中。我正在使用一个同时接受GET和POST的REST API。

不工作POST:

var request_post = new RestRequest ("folder/endpoint.php", Method.POST);
request_post.AddParameter("ref", "some/value");
response = client.Execute(request_post);
Console.WriteLine (response.Content);

错误是说ref参数是必需的。

工作GET:

var request_get = new RestRequest ("folder/endpoint.php", Method.GET);
request_get.AddParameter("ref", "some/value");
response = client.Execute(request_get);
Console.WriteLine (response.Content);

更新

可能是添加参数,但我需要将参数添加为表单。

1 个答案:

答案 0 :(得分:0)

谢谢,Matt

// POST request.
// 
// This method does not work!
// var request_post = new RestRequest ("folder/endpoint.php", Method.POST);
// request_post.AddParameter("ref", "some/value");
// 
// This method does work.
var endpoint =  String.Format("folder/endpoint.php?{0}={1}", 
          "ref", "some/value");
var request_post = new RestRequest (endpoint, Method.POST);
response = client.Execute(request_post);
// Print out headers.
foreach (var header in response.Headers){
          Console.WriteLine(header);
}
// Print response.
Console.WriteLine(response.Content)