有谁知道我如何发帖到 tagpacker网站(在 .Net 中有以下 API?因为不知何故我不明白对他们服务器的授权...
我目前使用的代码如下:
private readonly HttpWebRequest _httpWebRequest = (HttpWebRequest)
WebRequest.Create("https://tagpacker.com/api/users/{YourUserID}/tags");
public void Load()
{
_httpWebRequest.ContentType = "application/json";
_httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(_httpWebRequest.GetRequestStream()))
{
var json = "{\"user\":\"test\"," +
"\"password\":\"bla\"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)_httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
}
但我收到了以下消息:
{
"status": 401,
"message": "User not authorized",
"code": "USER_NOT_AUTHORIZED",
"url": "/unauthorizedHandler"
}
您从他们那里得到的唯一其他东西是“API 访问”代码,如下所示:1b3f314dd132b0015b5415b1:bd0ffe4b-a01e-4bf5-b1ed-12b24145d12d 其中第一部分是您的用户 ID,第二个是你的 API 代码 我猜?有没有人知道如何使用它? Tagpacker's Api FAQs are here.
最佳答案
tagpacker 团队的官方回答是,您需要在 header 中设置 api key ,如下所示(Java 示例):
URL url = new URL("https://tagpacker.com/api/users/<your_user_id>/links?limit=20");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("api_key", "<your_api_key>");
我将尝试在 C# 中执行此操作,然后再次编辑答案。
关于c# - 使用 HttpWebRequest 从 C# 连接到 Tagpacker.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41313219/