Portal SAMP
[Ajuda] ERROR: failed to parse response as JSON: '' - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] ERROR: failed to parse response as JSON: '' (/showthread.php?tid=4817)



ERROR: failed to parse response as JSON: '' - sabio - 24/06/2024

Código:

Código PHP:
#include "..\YSI-Includes\YSI_Coding\y_hooks"

hook OnGameModeInit()
{
    new RequestsClient:client RequestsClient("https://discord.com/api/webhooks/1254819501640515761/R2gzu84MXIHgiNUJX8UGnjsf0z8mWONfF9sTfBhYywOJMWbx_z_iqpyrbghgzaZN711k");

    SendWebHook(client"test-embed"0);

    return 1;
}

SendWebHook(RequestsClient:client, const title[], embed_color)
{
    RequestJSON(
        client,
        "",           
        HTTP_METHOD_POST
,
        "OnWebHookResponse",
        JsonObject(
            "embeds"JsonArray(
                JsonObject(
                    "title"JsonString("EMBED TEST"),
                    "color"JsonInt(embed_color),
                    "fields"JsonArray(
                        JsonObject(
                            "name"JsonString("`Players`"),
                            "value"JsonString("```prolog\n[0/50]\n```"),
                            "inline"JsonBool(true)
                        ),
                        JsonObject(
                            "name"JsonString("`IP`"),
                            "value"JsonString("```prolog\n[127.0.0.7]\n```"),
                            "inline"JsonBool(true)
                        )
                    ),
                    "author"JsonObject(
                        "name"JsonString("sabio_scripter"),
                        "icon_url"JsonString("https://i.postimg.cc/JhWsL9Hv/131c27a3f579208941f066d602bb32ee.webp")
                    ),
                    "footer"JsonObject(
                        "text"JsonString("bysabio")
                    ),
                    "timestamp"JsonString("2024-06-05T03:00:00.000Z"),
                    "image"JsonObject(
                        "url"JsonString("https://i.postimg.cc/JhWsL9Hv/131c27a3f579208941f066d602bb32ee.webp")
                    )
                )
            )
        ),
        RequestHeaders("Content-Type""application/json""Accept""application/json")
    );
    return 1;
}



forward OnWebHookResponse(Request:idstatus, const responseData[], len);
public 
OnWebHookResponse(Request:idstatus, const responseData[], len)
{
    if (status == 200) {
        printf("Webhook enviado com sucesso: %s"responseData);
    } else {
        printf("Falha ao enviar webhook. Status: %d, Resposta: %s"statusresponseData);
    }
    return 1;




console: 

Código PHP:
----------
Loaded log file"server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7-R2, (C)2005-2015 SA-MP Team

filterscripts 
""  (string)

Server Plugins
--------------
Loading pluginsscanf.dll

===============================

      sscanf plugin loaded.

        Version2.13.8

  
(c2022 Alex "Y_Less" Cole

===============================

  Loaded.
Loading pluginYSF.dll

==============================================
YSF 2.2 (compiled Sep 19 2021 13:01:03loaded
  
(c2008 Alex "Y_Less" Cole
  
(c2010 2018 kurta999
  
(c2018 2020 IllidanS4
Server version
0.3.7 R2-or R2-2Windows
==============================================

  Loaded.
Loading plugincrashdetect.dll
  CrashDetect plugin 4.21
  Loaded
.
Loading pluginstreamer.dll


*** Streamer Plugin v2.9.5 by Incognito loaded ***

  Loaded.
Loading pluginFCNPC.dll

-------------------------------------------------
    FCNPC Fully Controllable NPC v2.0.9
            Windows SA
-MP 0.3.7 R2
          Apr 17 2024 at 09
:11:14

  Author
:      OrMisicL (2013 2015)
  Continued byziggi    (2016 present)

  See full credits in the README.md file
-------------------------------------------------

Loading...

-------------------------------------------------
  ColAndreasv1.4.0

  Created By
:
    [uL]Chris42O
    
[uL]Slice
    
[uL]Pottus
-------------------------------------------------

Loading...
ColAndreas v1.4.0 Loaded.
  Loaded.
Loading pluginpawnraknet.dll
[Pawn.RakNetplugin v1.6.0 loading...
[
Pawn.RakNet]

    Pawn.RakNet 1.6.0 2016 2023
    
|--------------------------------
    Author and maintainerkatursis


    
CompiledFeb 12 2023 at 19:36:19
    
|--------------------------------------------------------------
    Repositoryhttps://github.com/katursis/Pawn.RakNet
    |--------------------------------------------------------------
    Wikihttps://github.com/katursis/Pawn.RakNet/wiki

  Loaded.
Loading plugindiscord-connector.dll
>> discord-connectorafb7e3b successfully loaded.
  Loaded.
Loading pluginsamp_bcrypt.dll
[SampBcrypt] [info]: Version0.4.0
  Loaded
.
Loading plugintextdraw-streamer.dll

=================================
|
                              |
|
    textdraw-streamer v2.0.3  |
|
            Loaded            |
|
                              |
|
  Coding:                      |
|
                              |
|
  Burak (Nexor)                |
|
                              |
|
  Compiled:                    |
|
                              |
|
  29.09.202316:49:07        |
|
                              |
|
  Github:                      |
|
                              |
|
  github.com/nexquery          |
|
                              |
|
  Discord:                    |
|
                              |
|
  benburakya Nexor#4730      |
|                              |
=================================

  Loaded.
Loading pluginrequests.dll
  Loaded
.
Loading pluginmysql.dll
>> plugin.mysqlR41-4 successfully loaded.
  Loaded.
Loading pluginnativechecker.dll
  Loaded
.
Loaded 12 plugins.


Started server on port7777with maxplayers50 lanmode is OFF.


Filterscripts
---------------
  Loaded 0 filterscripts.

No collision data found.


        ==============================================================
        |                                                            |
        |                                                            |
        |    YYYYYYY      YYYYYYY    SSSSSSSSSSSSSSS  IIIIIIIIII    |
        |    Y:::::Y      Y:::::Y  SS:::::::::::::::S I::::::::I    |
        |    Y:::::Y      Y:::::Y S:::::SSSSSS::::::S I::::::::I    |
        |    Y::::::Y    Y::::::Y S:::::S    SSSSSSS II::::::II    |
        |    YYY:::::Y  Y:::::YYY S:::::S              I::::I      |
        |      Y:::::Y Y:::::Y    S:::::S              I::::I      |
        |        Y:::::Y:::::Y      S::::SSSS            I::::I      |
        |        Y:::::::::Y        SS::::::SSSSS      I::::I      |
        |          Y:::::::Y          SSS::::::::SS    I::::I      |
        |          Y:::::Y              SSSSSS::::S    I::::I      |
        |          Y:::::Y                    S:::::S  I::::I      |
        |          Y:::::Y                    S:::::S  I::::I      |
        |          Y:::::Y        SSSSSSS    S:::::S II::::::II    |
        |        YYYY:::::YYYY    S::::::SSSSSS:::::S I::::::::I    |
        |        Y:::::::::::Y    S:::::::::::::::SS  I::::::::I    |
        |        YYYYYYYYYYYYY      SSSSSSSSSSSSSSS    IIIIIIIIII    |
        |                                                            |
        |                                                            |
        |                      (c2021 MPL v1.1                    |
        |            Alex "Y_Less" Cole and contributors.            |
        |                                                            |
        |                                                            |
        ==============================================================


==========================================
|
                                        |
|
  Generating codethis may take a    |
|
  little bit of time.  Note that this  |
|
  code generation works best with the  |
|
    JIT pluginwhich you are not      |
|
    currently using.  Get it here:    |
|
                                        |
|
      https://git.io/jit-plugin        |
|                                        |
|
            Please wait...            |
|
                                        |
|
            Done in 315ms!            |
|
                                        |
==========================================
  Filterscript '../scriptfiles/callbackfix.amx' loaded.
|
                                        |
Server:      0.3.7-R2 (W)              |
Started:    24 Jun 2024 18:44:12    |
|
                                        |
Compiler:    3.10.10 (Windows)        |
Includes:    0.3.7                    |
Codepage:    <none>                    |
Built:      24 Jun 2024 18:43:57    |
|
                                        |
YSI:        v05.10.0006              |
Master:      -1                        |
|
                                        |
JIT:        <none>                    |
Crashdetect: <found>                  |
|
                                        |
==========================================

Conexao bem sucedida com o Banco de Dados [localhost]

GAMEMODE VERSION: (1.0)
Creditos:sabio_scripter



Number of vehicle models
0
ERROR
failed to parse response as JSON''
Falha ao enviar webhookStatus204Resposta

Por que está aparecendo este erro no console? Estou usando o plugin requests do Southclaws.

Obs: a request funciona normalmente, só esse erro que está me incomodando.


RE: ERROR: failed to parse response as JSON: '' - BitSain - 25/06/2024

A mensagem de erro (ERROR: failed to parse response as JSON: ''") ocorre porque o plugin espera uma resposta em JSON, mas a resposta que está recebendo é vazia, mesmo que o webhook tenha sido enviado com sucesso..

O código de status 204 significa "No Content", indicando que o servidor processou a solicitação com sucesso, mas não está retornando nenhum conteúdo.


RE: ERROR: failed to parse response as JSON: '' - pushline - 25/06/2024

Retorna 204 por que a api de webhook do discord não retorna conteúdo no final de um post.
Porém neste código a única coisa que deverias "arrumar" seria colocar o "title" no JsonString na key 'title' (já que está EMBED TEST), e retirar o "Accept application/json" já que a api de webhook só necessita do content-type.

Código PHP:
"title"JsonString(title),

RequestHeaders("Content-Type""application/json"