有人知道我如何在.net中发布到tagpacker网站吗?因为不知怎的我不明白对他们服务器的授权…
我当前使用的代码如下:
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代码我猜是?有人知道怎么用这个吗?API
最佳答案
TagPacker团队的官方回答是,您需要在头中设置API键,如下所示(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/