Web服务标头

时间:2016-05-02 18:15:52

标签: c# web-services

我正在尝试在标头中进行Web服务调用并包含和授权cookie。

我看到另一个网站使用fiddler执行此操作,调用看起来像 -

GET url/services/events HTTP/1.1
Host: url
Connection: keep-alive
Accept: application/json
X-Auth-Token: 33d131bb-37b4-4d87-b646-6edccab4f294
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
Content-Type: application/json
Referer: url/api-docs/index.html
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cookie: knownUser=true

如何编码“X-Auth-Token:33d131bb-37b4-4d87-b646-6edccab4f294”。

这是我的C#代码。

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("X-Auth-Token", "33d131bb-37b4-4d87-b646-6edccab4f294");

HttpResponseMessage response = client.PostAsync(new Uri("url?keywords=Taylor%20Swift&eventType=CONCERT&city=Mexico%20City"), new StringContent(JsonConvert.SerializeObject(sp), Encoding.UTF8, "application/json")).Result;

但我一直收到500错误。 (StatusCode:500,ReasonPhrase:'内部服务器错误')

在Web服务调用中传递该令牌的语法是什么?

0 个答案:

没有答案