【发布时间】:2015-08-04 01:11:41
【问题描述】:
我尝试按照帖子访问 Access ASANA via windows powershell using APIKEY 此处找到的 asana api。以下是我正在使用的代码和收到的错误消息:
$apikey="******.***************"
#Add colon
$authinfo=$apikey+":";
$string1 = $authinfo
Write-Host $string1 -ForeGroundColor Green
#Encoding format
$enc = [system.Text.Encoding]::UTF8
#get bytes
$data1 = $enc.GetBytes($string1)
#convert to 64 bit
$mykey=[System.Convert]::ToBase64String($data1)
Write-Host $mykey -ForeGroundColor Green
$url="https://app.asana.com/api/1.0/users"
$request = [System.Net.WebRequest]::Create($url)
$authorization = "Authorization: Basic " + $myKey
Write-Host $authorization -ForeGroundColor Green
$request.Headers.Add($authorization)
#$request.Headers.Add("Authorization: BASIC $mykey")
$response = $request.GetResponse()
Write-Host $Response -ForeGroundColor Green
并收到以下错误:
使用“0”参数调用“GetResponse”的异常:“操作已超时” 在行:26 字符:1 + $response = $request.GetResponse() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
【问题讨论】:
-
url 和 auth 标头对我来说看起来不错。即使您提出了错误的请求,也不应该超时。我对 powershell 不熟悉 - 你必须做一些特别的事情来发出 HTTPS 请求吗?要尝试的另一件事是不同的请求,即尝试
/users/me而不是/users,看看它是否也超时。 -
我同意@GregS。到目前为止看起来不错,超时就意味着;完全没有反应。这不是正常工作的 Web 应用程序的典型特征。除非证书有问题(过期、主机/CN 不匹配等),否则 HTTPS 不需要什么特别的东西。我不知道您使用的是哪个版本的 PowerShell,但您可以在 PowerShell 3 及更高版本中使用
Invoke-WebRequest或Invoke-RestMethod。它们比[System.Net.WebRequest]更容易使用,但我怀疑它是否有助于解决您的问题。 -
谢谢,我试过
Invoke-RestMethod和Invoke-WebRequest没有任何额外的运气。我仍然收到与以前相同的错误。
标签: powershell asana