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 –