C#相当于php帖子

时间:2015-08-10 15:30:35

标签: c# php rest

我有以下php请求...

$response = $client->put($uri, ['headers' =>  ['X-Auth-Token'  => 'YOUR_TOKEN'],
                                  'json'    =>  ['soccerseasons' => '362' ]

我不确定如何将此请求转换为' PUT'在C#中使用WebAPI库。这是我到目前为止所尝试过的。

HttpRequestMessage content = new HttpRequestMessage();
content.Headers.Add("X-Auth-Token", "[YOUR-TOKEN]");
content.Content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("soccerseasons", "362")});

var formContent = new FormUrlEncodedContent(new[]
{
       new KeyValuePair<string, string>("X-Auth-Token", "[YOUR_TOKEN]"),
       new KeyValuePair<string, string>("soccerseasons", "362")
});

var channelResult = client.PutAsync(new Uri("http://api.football-data.org/alpha/notifications"),formContent);
var res = channelResult.Result;

但是,每次通过HttpClient对象调用都会返回429错误:调用PostAsync时请求太多。

我确定这对某人来说是一个简单的问题。什么是上述PHP调用的C#等价物?

0 个答案:

没有答案