【发布时间】:2014-02-10 21:43:25
【问题描述】:
我正用头撞墙,试图将工作的 curl 命令转换为 c# WebRequest。
我已经阅读了很多帖子,我非常确定我的代码是正确的,但它仍然无法正常工作。
谁能看看我做错了什么?
这是有效的 curl 命令:
curl -k -u x:reallylongstring -H "Content-Type: application/json" https://api.somewhere.com/desk/external_api/v1/customers.json
这是我用c#写的代码:
WebRequest wrGETURL;
wrGETURL = WebRequest.Create("https://api.somewhere.com/desk/external_api/v1/customers.json");
wrGETURL.Method = "GET";
wrGETURL.ContentType = "application/json";
wrGETURL.Credentials = new NetworkCredential("x", "reallylongstring");
Stream objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
string responseFromServer = objReader.ReadToEnd();
但是 api 响应:
The remote server returned an error: (406) Not Acceptable.
任何帮助将不胜感激!
谢谢
【问题讨论】:
-
这是.net - Making a cURL call in C# 的副本吗?那里似乎有更多的答案。