groovy - Can't understand why Google Translate REST API returns HTTP 400 -


using camel route sending post request google translate api:

from("direct:start"). setheader(exchange.http_method, constant('post')). setheader('x-http-method-override', constant('get')). setbody(constant('q=hello')).                                                                                                                                                                                                            log(logginglevel.info, 'sourcingtool', '${body}'). to("https://www.googleapis.com/language/translate/v2?key=${api_key}&target=fr"). to('stream:out') 

for reason getting http 400. seeing problem in request?

update 1 when i'm using curl , sending similar request, everyting works charm:

curl -xpost -h "x-http-method-override:get" --data "q=hello" "https://www.googleapis.com/language/translate/v2?key=my_api_key&target=fr"

the answer simple. needed explicitly set content_type:

from("direct:start"). setheader(exchange.http_method, constant('post')). setheader(exchange.content_type, constant('application/x-www-form-urlencoded')). // 1 did trick setheader('x-http-method-override', constant('get')). setbody(constant('q=hello')).                                                                                                                                                                                                            log(logginglevel.info, 'sourcingtool', '${body}'). to("https://www.googleapis.com/language/translate/v2?key=${api_key}&target=fr"). to('stream:out') 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -