• 0
gabriel_oliveira

Erro ao enviar descrição que contenha o caractere '%'.

Question

Amigos, não consigo enviar uma descrição que contenha o caractere '%'.

Alguém já passou por isso?

  1. message"Request body is not properly encoded as application/x-www-form-urlencoded type. Root cause: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "-P""

 

 
$headers = array(
    'Accept'=>'application/json',
    'Content-Type'=>'application/x-www-form-urlencoded; charset=UTF-8',
);

 

Unirest\Response Object
(
    [code] => 400
    [raw_body] => {"message":"Request body is not properly encoded as application/x-www-form-urlencoded type. Root cause: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: \" P\"","error":"bad_request","status":400,"cause":[]}
    [body] => stdClass Object
        (
            [message] => Request body is not properly encoded as application/x-www-form-urlencoded type. Root cause: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: " P"
            [error] => bad_request
            [status] => 400
            [cause] => Array
                (
                )

        )

    [headers] => Array
        (
            [0] => HTTP/1.1 400 Bad Request
            [Content-Type] => application/json;charset=UTF-8
            [Transfer-Encoding] => chunked
            [Connection] => keep-alive
            [Date] => Mon, 08 Oct 2018 18:13:13 GMT
            [X-API-Name] => syi-api
            [X-API-Version] => 1.00
            [Vary] => Accept,Accept-Encoding
            [Cache-Control] => max-age=0
            [X-Content-Type-Options] => nosniff
            [X-Request-Id] => d037e9aa-3g97-42e0-9864-56a3550d1fd4
            [X-Frame-Options] => DENY
            [X-XSS-Protection] => 1; mode=block
            [Access-Control-Allow-Origin] => *
            [Access-Control-Allow-Headers] => Content-Type
            [Access-Control-Allow-Methods] => PUT, GET, POST, DELETE, OPTIONS
            [Access-Control-Max-Age] => 86400
            [X-Cache] => Error from cloudfront
            [Via] => 1.1 c82f36427d9eb6a074049d3a5516a4bf.cloudfront.net (CloudFront)
            [X-Amz-Cf-Id] => iT678b-pjiry7336jjHqrZTijhtRffDU990SckcJNcSr49KWfxnm8pA==
        )

)

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
17 hours ago, gabriel_oliveira said:

Amigos, não consigo enviar uma descrição que contenha o caractere '%'.

Alguém já passou por isso?

  1. message"Request body is not properly encoded as application/x-www-form-urlencoded type. Root cause: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "-P""

 

 

$headers = array(
    'Accept'=>'application/json',
    'Content-Type'=>'application/x-www-form-urlencoded; charset=UTF-8',
);

 


Unirest\Response Object
(
    [code] => 400
    [raw_body] => {"message":"Request body is not properly encoded as application/x-www-form-urlencoded type. Root cause: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: \" P\"","error":"bad_request","status":400,"cause":[]}
    [body] => stdClass Object
        (
            [message] => Request body is not properly encoded as application/x-www-form-urlencoded type. Root cause: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: " P"
            [error] => bad_request
            [status] => 400
            [cause] => Array
                (
                )

        )

    [headers] => Array
        (
            [0] => HTTP/1.1 400 Bad Request
            [Content-Type] => application/json;charset=UTF-8
            [Transfer-Encoding] => chunked
            [Connection] => keep-alive
            [Date] => Mon, 08 Oct 2018 18:13:13 GMT
            [X-API-Name] => syi-api
            [X-API-Version] => 1.00
            [Vary] => Accept,Accept-Encoding
            [Cache-Control] => max-age=0
            [X-Content-Type-Options] => nosniff
            [X-Request-Id] => d037e9aa-3g97-42e0-9864-56a3550d1fd4
            [X-Frame-Options] => DENY
            [X-XSS-Protection] => 1; mode=block
            [Access-Control-Allow-Origin] => *
            [Access-Control-Allow-Headers] => Content-Type
            [Access-Control-Allow-Methods] => PUT, GET, POST, DELETE, OPTIONS
            [Access-Control-Max-Age] => 86400
            [X-Cache] => Error from cloudfront
            [Via] => 1.1 c82f36427d9eb6a074049d3a5516a4bf.cloudfront.net (CloudFront)
            [X-Amz-Cf-Id] => iT678b-pjiry7336jjHqrZTijhtRffDU990SckcJNcSr49KWfxnm8pA==
        )

)

Você precisa converter para string unicode tipo % -> \u0025

Você está usando json_encode ?

Share this post


Link to post
Share on other sites
  • 0
2 hours ago, gbandoni said:

Você precisa converter para string unicode tipo % -> \u0025

Você está usando json_encode ?

Estou sim utilizando o json_encode(). Apenas quando coloco o caractere '%', é que não consigo completar a solicitação. Ainda estou tentando.

Share this post


Link to post
Share on other sites
  • 0
18 minutes ago, gabriel_oliveira said:

Estou sim utilizando o json_encode(). Apenas quando coloco o caractere '%', é que não consigo completar a solicitação. Ainda estou tentando.

Eu testei aqui e coloquei % como hexa e foi .

Pode mostrar os dados que voce esta enviando ? (pode remover os dados sensíveis)

Share this post


Link to post
Share on other sites
  • 0
2 minutes ago, gbandoni said:

Eu testei aqui e coloquei % como hexa e foi .

Pode mostrar os dados que voce esta enviando ? (pode remover os dados sensíveis)

Acabei de conseguir, atualizando os header da seguinte maneira:

$headers = array(
    'Accept:application/json',
    'Content-Type:application/x-www-form-urlencoded; charset=UTF-8',
);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now