我一直在跟踪这个在cURL中调用C#,它试图使用LiveChat API发出请求,并在我的C#应用程序上接收结果,
请求应按以下方式填写,如http://developers.livechatinc.com/rest-api/#!introduction中所解释的:
curl "https://api.livechatinc.com/agents" \
-u john.doe@mycompany.com:c14b85863755158d7aa5cc4ba17f61cb \
-H X-API-Version:2 这就是我在C#中所做的:
static void Main(string[] args)
{
RequestTest();
Console.ReadKey();
}
private static async void RequestTest()
{
var client = new HttpClient();
// Create the HttpContent for the form to be posted.
var requestContent = new FormUrlEncodedContent(new[] {new KeyValuePair<string, string>("myemail:myapikey", "X-API-Version:2"),});
// Get the response.
HttpResponseMessage response = await client.PostAsync(
"https://api.livechatinc.com/agents",
requestContent);
// Get the response content.
HttpContent responseContent = response.Content;
// Get the stream of the content.
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
// Write the output.
Console.WriteLine(await reader.ReadToEndAsync());
}
}结果似乎总是一样“不能发到/agents”
发布于 2015-06-05 10:47:57
你在这里做手术。这是为创建一个新代理而保留的,并要求您发送一个JSON请求有效负载。见此处:developers.livechatinc.com/rest-api/#create-agent
您想要做的是一个GET操作:developers.livechatinc.com/rest-api/#get-single-agent
与使用PostAsync不同,您需要创建一个HttpRequestMessage,将方法设置为GET,设置头部,然后使用SendAsync。参见这里的解决方案:向HttpClient添加Http头
记住,对于REST:
POST = Create Operations,
GET = Read Operations,
PUT = Update Operations,
DELETE = Delete Operationshttps://stackoverflow.com/questions/30663751
复制相似问题