fukamachi / dexador

A fast HTTP client for Common Lisp
http://ultra.wikia.com/wiki/Dexador
379 stars 41 forks source link

dex:post gives 415 unsupported media type #163

Closed davidbe closed 12 months ago

davidbe commented 12 months ago

Hi,

I want to convert some python code to Common Lisp - but it fails and I don't have a clue... It looks like the same issue as issue #81 . But the clues given, don't work.

Python-code:


import requests

h = {
    'User-Agent': 'VTM_GO/14.231023 (be.vmma.vtm.zenderapp; build:18041; Android 23) okhttp/4.11.0',
    'x-app-version': '14',
    'x-persgroep-mobile-app': 'true',
    'x-persgroep-os': 'android',
    'x-persgroep-os-version': '28',
}

url = "https://login2.vtm.be/device/authorize"

f = { 'client_id': 'vtm-go-androidtv'}

res = requests.request('POST', url, data=f, headers=h)
print(res.text)

results in: {"user_code":"RLGTNZ","device_code":"NGJH22UluH-oOONjhJZrFW1M2mne6tu4QcfqORSOQww","interval":2,"verification_uri_complete":"https://login2.vtm.be/androidtv?user_code=RLGTNZ","verification_uri":"https://login2.vtm.be/androidtv","expires_in":300} Which is good.

But this Common Lisp code doesn't work:

(defvar *auth-url*
  "https://login2.vtm.be/device/authorize")

(defvar *auth-headers*
  '(("User-Agent" . "VTM_GO/14.231023 (be.vmma.vtm.zenderapp; build:18041; Android 23) okhttp/4.11.0")
    ("x-app-version" . "14")
    ("x-persgroep-mobile-app" . "true")
    ("x-persgroep-os" . "android")
    ("x-persgroep-os-version" . "28")))

(defvar *auth-content*
  (cl-json:encode-json-to-string
   '(("client_id" . "vtm-go-androidtv"))))

(defun get-auth-token ()
  (dex:post *auth-url*
           :headers *auth-headers*
           :content *auth-content*
           :verbose t))

Results in error:

An HTTP request to "https://login2.vtm.be/device/authorize" returned 415 unsupported media type.
{"timestamp":"2023-11-30T19:52:46.107+00:00","status":415,"error":"Unsupported Media Type","path":"/device/authorize"}

Verbose output:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
POST /device/authorize HTTP/1.1
User-Agent: VTM_GO/14.231023 (be.vmma.vtm.zenderapp; build:18041; Android 23) okhttp/4.11.0
Host: login2.vtm.be
Accept: */*
Content-Type: text/plain
Content-Length: 32
X-App-Version: 14
X-Persgroep-Mobile-App: true
X-Persgroep-Os: android
X-Persgroep-Os-Version: 28
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/json
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Referrer-Policy: origin-when-cross-origin
Content-Security-Policy: frame-ancestors 'self'
Expect-CT: max-age=300, report-uri https://f148af276260adc1ec7580e9f4b445b4.report-uri.com/r/t/ct/reportOnly
Strict-Transport-Security: max-age=300; includeSubDomains
X-Robots-Tag: noindex, nofollow
Accept: application/x-www-form-urlencoded
Content-Length: 118
Expires: Thu, 30 Nov 2023 19:45:24 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Thu, 30 Nov 2023 19:45:24 GMT
Connection: close
Set-Cookie: x-oidcp-debugid=PIP-6fc0a613-8c24-4109-a7f8-52f7bbb0b637-unknown; Path=/; Secure; HttpOnly
Access-Control-Allow-Origin: *
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Content-Type here is text/plain. In #81 it was suggested that it might be encoded in www-x-form-urlencoded with cl-json:encode-json-to-string, but I guess it fails? How can I find this out?

fukamachi commented 12 months ago

I don’t get if the body need to be url-encoded or json, but you can specify the content-type in the HTTP headers like others. Dexador will use www-x-url-encoded automatically if the content is an association list.

davidbe commented 12 months ago

Thank you for your response, it got me started to think in the right direction. Because it API is described with few documentation and based on reverse engineering, I thought the body was like json, but it just had to be a string "client_id=vtm-go-androidtv".