WSE 2012 R2 WebApi 调用的 AppName、AppPublisher 和 AppVersion header 值是多少?
What are the AppName, AppPublisher and AppVersion header values for a WSE 2012 R2 WebApi call?
我正在尝试查询我的 Server 2012 Essentials R2 服务器以确定给定设备的最新客户端备份时间,以便我可以在登录时为健忘的用户显示 nag 屏幕。 (它们在笔记本电脑上,所以我不能依赖机器在自动 window 期间可用。)
我能找到的最接近文档的是:(https://msdn.microsoft.com/en-us/library/jj713757.aspx)
GET services/builtin/DeviceManagement.svc/devices/index/{index}/count/{count}
但是需要先调用才能获取令牌:(https://msdn.microsoft.com/en-us/library/jj713753.aspx)
GET https://www.contoso.com/services/builtin/session.svc/login HTTP/1.1
Accept: application/xml
Host: servername
Authorization: Basic VXNlcjpQYXNzd29yZCE=
AppName: Sample App Name
AppPublisher: publisher
AppVersion: 1.0
有谁知道对于标准的 WSE 2012 R2 安装,最后三个 headers 的值应该是多少?或者如何发现它们?该文档在此不提供任何帮助。
或者如果有人知道更好的方法,请告诉我。
好的,我开始工作了。代码如下。
事实证明,AppName header 的值是无关紧要的——它可以是任何字符串,但不能为空。
通过查看 GAC Wssg.WebApi.Framework
中的 WSE 源代码,我已经知道它不能为空,但代码分离到几乎不可能找出进程选择的程度一旦 RemoteConnectionClientInfo
object 被放入 HTTP session.
误导我的部分是——想想看——文档本身。
Authentication page 上的密码后有一个爆炸 (!
),表明它应该在编码之前跟踪实际密码。这就是我收到身份验证错误的原因,而我又(错误地)将其归因于文档中的声明:“在 HTTP header 字段中添加 Appname、Apppublisher 和 Appversion 值。这些还需要值才能登录。"
所以当我清理完所有这些后,我就开始航行了。
文档中还有其他错误。在 Devices page 上,我们被告知 Host
header 应该设置为域名,并且应该添加 Content-Length
header。
这些都不正确。 Host
header 应该是服务器的主机名,不应该有 Content-Length
header(那是响应 header,不是请求 header) .
还有……!经过这一切,我发现返回的设备信息不包含最近的备份时间。我将不得不为此进一步挖掘。但至少现在我可以连接了。
所以微软的不完整、不准确和草率的文档让我花了一天的时间。希望其他人可以使用它并避免我经历的痛苦。
Module Main
Public Sub Main()
Dim aCredentials() As Byte
Dim _
oAuthenticateUri,
oDeviceListUri As Uri
Dim _
sCanary,
sCookie,
sDevices As String
aCredentials = Encoding.ASCII.GetBytes($"{USERNAME}:{PASSWORD}")
Using oClient As New HttpClient
oAuthenticateUri = New Uri($"https://{HOST}/services/builtin/session.svc/login")
oDeviceListUri = New Uri($"https://{HOST}/services/builtin/devicemanagement.svc/devices/index/0/count/99")
oClient.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/xml"))
oClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Basic", Convert.ToBase64String(aCredentials))
oClient.DefaultRequestHeaders.Host = HOST
oClient.DefaultRequestHeaders.Add("AppPublisher", String.Empty)
oClient.DefaultRequestHeaders.Add("AppVersion", String.Empty)
oClient.DefaultRequestHeaders.Add("AppName", "None")
Using oAuthenticateResponse As HttpResponseMessage = oClient.GetAsync(oAuthenticateUri).Result
If oAuthenticateResponse.IsSuccessStatusCode Then
sCanary = oAuthenticateResponse.Headers.Single(Function(Pair) Pair.Key = CANARY_HEADER).Value(0)
sCookie = Split(oAuthenticateResponse.Headers.Single(Function(Pair) Pair.Key = COOKIE_HEADER).Value(0), ";")(0)
oClient.DefaultRequestHeaders.Clear()
oClient.DefaultRequestHeaders.Host = HOST
oClient.DefaultRequestHeaders.Add(CANARY_HEADER, sCanary)
oClient.DefaultRequestHeaders.Add(COOKIE_HEADER, sCookie)
Using oDeviceListResponse As HttpResponseMessage = oClient.GetAsync(oDeviceListUri).Result
If oDeviceListResponse.IsSuccessStatusCode Then
sDevices = oDeviceListResponse.Content.ReadAsStringAsync.Result
Else
Console.WriteLine("{0} ({1})", oDeviceListResponse.StatusCode, oDeviceListResponse.ReasonPhrase)
End If
End Using
Else
Console.WriteLine("{0} ({1})", oAuthenticateResponse.StatusCode, oAuthenticateResponse.ReasonPhrase)
End If
End Using
End Using
End Sub
Private Const CANARY_HEADER As String = "Canary"
Private Const COOKIE_HEADER As String = "Set-Cookie"
Private Const USERNAME As String = "domain.admin"
Private Const PASSWORD As String = "admin.password"
Private Const HOST As String = "server"
End Module
我正在尝试查询我的 Server 2012 Essentials R2 服务器以确定给定设备的最新客户端备份时间,以便我可以在登录时为健忘的用户显示 nag 屏幕。 (它们在笔记本电脑上,所以我不能依赖机器在自动 window 期间可用。)
我能找到的最接近文档的是:(https://msdn.microsoft.com/en-us/library/jj713757.aspx)
GET services/builtin/DeviceManagement.svc/devices/index/{index}/count/{count}
但是需要先调用才能获取令牌:(https://msdn.microsoft.com/en-us/library/jj713753.aspx)
GET https://www.contoso.com/services/builtin/session.svc/login HTTP/1.1
Accept: application/xml
Host: servername
Authorization: Basic VXNlcjpQYXNzd29yZCE=
AppName: Sample App Name
AppPublisher: publisher
AppVersion: 1.0
有谁知道对于标准的 WSE 2012 R2 安装,最后三个 headers 的值应该是多少?或者如何发现它们?该文档在此不提供任何帮助。
或者如果有人知道更好的方法,请告诉我。
好的,我开始工作了。代码如下。
事实证明,AppName header 的值是无关紧要的——它可以是任何字符串,但不能为空。
通过查看 GAC Wssg.WebApi.Framework
中的 WSE 源代码,我已经知道它不能为空,但代码分离到几乎不可能找出进程选择的程度一旦 RemoteConnectionClientInfo
object 被放入 HTTP session.
误导我的部分是——想想看——文档本身。
Authentication page 上的密码后有一个爆炸 (!
),表明它应该在编码之前跟踪实际密码。这就是我收到身份验证错误的原因,而我又(错误地)将其归因于文档中的声明:“在 HTTP header 字段中添加 Appname、Apppublisher 和 Appversion 值。这些还需要值才能登录。"
所以当我清理完所有这些后,我就开始航行了。
文档中还有其他错误。在 Devices page 上,我们被告知 Host
header 应该设置为域名,并且应该添加 Content-Length
header。
这些都不正确。 Host
header 应该是服务器的主机名,不应该有 Content-Length
header(那是响应 header,不是请求 header) .
还有……!经过这一切,我发现返回的设备信息不包含最近的备份时间。我将不得不为此进一步挖掘。但至少现在我可以连接了。
所以微软的不完整、不准确和草率的文档让我花了一天的时间。希望其他人可以使用它并避免我经历的痛苦。
Module Main
Public Sub Main()
Dim aCredentials() As Byte
Dim _
oAuthenticateUri,
oDeviceListUri As Uri
Dim _
sCanary,
sCookie,
sDevices As String
aCredentials = Encoding.ASCII.GetBytes($"{USERNAME}:{PASSWORD}")
Using oClient As New HttpClient
oAuthenticateUri = New Uri($"https://{HOST}/services/builtin/session.svc/login")
oDeviceListUri = New Uri($"https://{HOST}/services/builtin/devicemanagement.svc/devices/index/0/count/99")
oClient.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/xml"))
oClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Basic", Convert.ToBase64String(aCredentials))
oClient.DefaultRequestHeaders.Host = HOST
oClient.DefaultRequestHeaders.Add("AppPublisher", String.Empty)
oClient.DefaultRequestHeaders.Add("AppVersion", String.Empty)
oClient.DefaultRequestHeaders.Add("AppName", "None")
Using oAuthenticateResponse As HttpResponseMessage = oClient.GetAsync(oAuthenticateUri).Result
If oAuthenticateResponse.IsSuccessStatusCode Then
sCanary = oAuthenticateResponse.Headers.Single(Function(Pair) Pair.Key = CANARY_HEADER).Value(0)
sCookie = Split(oAuthenticateResponse.Headers.Single(Function(Pair) Pair.Key = COOKIE_HEADER).Value(0), ";")(0)
oClient.DefaultRequestHeaders.Clear()
oClient.DefaultRequestHeaders.Host = HOST
oClient.DefaultRequestHeaders.Add(CANARY_HEADER, sCanary)
oClient.DefaultRequestHeaders.Add(COOKIE_HEADER, sCookie)
Using oDeviceListResponse As HttpResponseMessage = oClient.GetAsync(oDeviceListUri).Result
If oDeviceListResponse.IsSuccessStatusCode Then
sDevices = oDeviceListResponse.Content.ReadAsStringAsync.Result
Else
Console.WriteLine("{0} ({1})", oDeviceListResponse.StatusCode, oDeviceListResponse.ReasonPhrase)
End If
End Using
Else
Console.WriteLine("{0} ({1})", oAuthenticateResponse.StatusCode, oAuthenticateResponse.ReasonPhrase)
End If
End Using
End Using
End Sub
Private Const CANARY_HEADER As String = "Canary"
Private Const COOKIE_HEADER As String = "Set-Cookie"
Private Const USERNAME As String = "domain.admin"
Private Const PASSWORD As String = "admin.password"
Private Const HOST As String = "server"
End Module