0
我一直在关注这个Making a cURL call in C#试图让与卷曲的ID登录API的请求和接收我的C#应用程序的结果,C#请求 - API ID登录
请求应被填上以下内容作为解释在:http://developers.livechatinc.com/rest-api/#!introduction
curl "https://api.livechatinc.com/agents" \
-u [email protected]: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());
}
}
结果似乎是百达相同的 “无法开机自检/代理”
我想你想要做一个GET请求。不是POST。 POST用于创建新的代理程序:http://developers.livechatinc.com/rest-api/#create-agent(并且需要您发送定义要创建的新代理程序的JSON请求负载)。你想这个:http://developers.livechatinc.com/rest-api/#get-single-agent –
@OliverMcPhee你是对的,但我怎么能添加“-u [email protected]:c14b85863755158d7aa5cc4ba17f61cb \ -H X-API-Version:2“ using a client.GetAsync method – EchO
看看这个线程的答案:http://stackoverflow.com/questions/12022965/adding-http-headers-to-httpclient -Asp网的Web-API –