首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#请求- API LiveChat

C#请求- API LiveChat
EN

Stack Overflow用户
提问于 2015-06-05 10:02:42
回答 1查看 531关注 0票数 0

我一直在跟踪这个在cURL中调用C#,它试图使用LiveChat API发出请求,并在我的C#应用程序上接收结果,

请求应按以下方式填写,如http://developers.livechatinc.com/rest-api/#!introduction中所解释的:

代码语言:javascript
复制
curl "https://api.livechatinc.com/agents" \
    -u john.doe@mycompany.com:c14b85863755158d7aa5cc4ba17f61cb \
    -H X-API-Version:2 

这就是我在C#中所做的:

代码语言:javascript
复制
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”

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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:

代码语言:javascript
复制
POST = Create Operations,
GET = Read Operations,
PUT = Update Operations,
DELETE = Delete Operations
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30663751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档