【发布时间】:2013-07-24 22:38:11
【问题描述】:
我正在尝试创建一个 POST 请求,但无法正常工作。
这是请求的格式,有 3 个参数,accountidentifier / type / seriesid
http://someSite.com/api/User_Favorites.php?accountid=accountidentifier&type=type&seriesid=seriesid
这是我的 C#
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri("http://somesite.com");
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("accountidentifier", accountID),
new KeyValuePair<string, string>("type", "add"),
new KeyValuePair<string, string>("seriesid", seriesId),
});
httpClient.PostAsync("/api/User_Favorites.php", content);
}
有什么想法吗?
【问题讨论】:
-
你能调试看看调用post时httpClient的完整uri是什么吗?
-
您提到的参数是
URI的一部分(查询部分,在?之后),但您将它们发送为content。 -
@Cubicle.Jockey 真的找不到。
-
@user1908061 该死的,你能给我一个使用参考什么的吗?
-
@allocator 嗯,HTTP 的维基百科文章?真的没什么好说的。您请求 URI
/api/User_Favorites.php,但查询部分 (?accountid=...) 也是您要请求的 URI 的一部分并且您将其省略。另一方面,您显然甚至不知道此 API 期望发送的内容是什么。你应该先弄清楚这一点,这是我们不可能知道的。