3

Can someone help me to create classic asp code from the CURL request below?

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

I tried the sample code below, but it didn't work.

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

And it throws the below error message at line Call.Send()

WinHttp.WinHttpRequest error '80090326'

The message received was unexpected or badly formatted.

user692942
  • 16,398
  • 7
  • 76
  • 175
Lucy
  • 73
  • 1
  • 9
  • [Documentation](https://manual.seafile.com/develop/web_api.html#shared-libraries) for reference. – user692942 Oct 21 '17 at 09:59
  • [Looks like my code that](https://stackoverflow.com/a/37462944/692942). It definitely works so if you’re getting an error its likely because your not passing the correct `Content-Type` or missing some requirements. – user692942 Oct 21 '17 at 10:03

1 Answers1

2

The issue is not the code, I've just tested your curl call with version 7.56.0 and here are the results;

First I tried the command in your question, which failed;

>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.

I guessed it didn't like the single quotes used for the HTTP Authorization header so replaced them and got this;

>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.

The problem here is the error:

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

which will happen regardless of what method you use to call the API.

Checking the address

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

in a browser leads to a warning that the site is not secure in Google Chrome and using an SSL checker it appears the names do not match on the SSL certificate.

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.

user692942
  • 16,398
  • 7
  • 76
  • 175