2017-10-20 328 views
2

有人可以幫我從下面的CURL請求創建經典的asp代碼嗎?在經典的ASP CURL請求

curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/beshared-repos/" 

我試過下面的示例代碼,但它沒有工作。

Dim http: Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1") 
Dim url: url = "https://cloud.seafile.com/api2/beshared-repos/" 

Dim data: data = "token=f2210dacd9c6ccb8133606d94ff8e61d99b477fd" 

With http 
    Call .Open("GET", url, False) 
    Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") 
    Call .SetRequestHeader("Authorization", "Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd") 
    Call .Send() 
End With 

If Left(http.Status, 1) = 2 Then 
    'Request succeeded with a HTTP 2xx response, do something... 
Else 
    'Output error 
    Call Response.Write("Server returned: " & http.Status & " " & http.StatusText) 
End If 

而且它拋出在行Call.Send()

WinHttp.WinHttpRequest error '80090326'

The message received was unexpected or badly formatted.

+0

[Documentation](https://manual.seafile.com/develop/web_api.html#shared-libraries)供參考。 – Lankymart

+0

[看起來像我的代碼](https://stackoverflow.com/a/37462944/692942)。它絕對有效,所以如果你得到一個錯誤,可能是因爲你沒有傳遞正確的「Content-Type」或缺少一些要求。 – Lankymart

回答

1

問題下面的錯誤消息不是代碼,我剛剛與7.56.0版本,這裏測試curl通話是結果;

首先我試着在你的問題中的命令,失敗了;

>curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/beshared-repos/" 

curl: (6) Could not resolve host: Token 
curl: (6) Could not resolve host: f2210dacd9c6ccb8133606d94ff8e61d99b477fd' 
curl: (35) schannel: SNI or certificate check failed: SEC_E_WRONG_PRINCIPAL (0x80090322) - The target principal name is incorrect. 

我猜想它不喜歡用於HTTP授權標題的單引號,所以替換它們並得到這個;

>curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" "https://cloud.seafile.com/api2/beshared-repos/" 

curl: (35) schannel: SNI or certificate check failed: SEC_E_WRONG_PRINCIPAL (0x80090322) - The target principal name is incorrect. 

這裏的問題是錯誤:

schannel: SNI or certificate check failed: SEC_E_WRONG_PRINCIPAL (0x80090322) - The target principal name is incorrect.

不管你用什麼方法來調用API,它會發生。

檢查在瀏覽器的地址

https://cloud.seafile.com/api2/beshared-repos/ 

導致警告,該網站未在谷歌瀏覽器保護和利用SSL checker它出現的名稱不匹配上的SSL證書。

None of the common names in the certificate match the name that was entered (cloud.seafile.com). You may receive an error when accessing this site in a web browser. Learn more about name mismatch errors .

+0

謝謝@Lankymart的反饋,問題是SSL證書! – RAJ