retrofit 2: POST JSON body and XML response - post

I would like to know if it is posible send a request with a JSON body and get the XML response with retrofit 2.
If I add two .addFactoryConverter() methods retrofit just use the first one for both the request and the response.
Thank you for your help.

With the following code I could solve the problem. https://github.com/square/retrofit/blob/master/samples/src/main/java/com/example/retrofit/JsonAndXmlConverters.java

Related

How to pass data to IFTTT WebHook?

I have a task to add row into Google Sheet when WebHook received. Now I'm trying to setup IFTTT but have some problem
It says that I should use URL like https://maker.ifttt.com/trigger/{event}/with/key/{my_key} and that is ok I can do it. But it needs to send some data in request and the only way my system can do it appends it to query string like https://maker.ifttt.com/trigger/{event}/with/key/{my_key}?name1=Alex&name2=Helen
But IFTTT doesn't see my data. it says that it can see data in attached JSON but I can't use JSON.
So is there any way to pass my data to IFTT in a query string or shell I forgot IFTTT and investigate how to connect directly to Google Sheet?
IFTTT Maker webhooks can only take data with keys of "value1", "value2", and "value3". Try sending it with:
https://maker.ifttt.com/trigger/{event}/with/key/{my_key}?value1=Alex&value2=Helen
Try using https://bitly.com/ which will shorten and convert the query params to a path param. That worked for me.
First thing first, Web hooks are designed to accept data using POST method only and here you are sending data using GET, which is obviously not going to work, i guess.
Second, in order to get it work, one way is to use cURL request and send your JSON in Body with POST method.

Reading response headers in Swagger

I am using swagger 2.1.0. I am able to send a header in a request, thanks to this example.
But now my question, the key which is to send with this example-call is received in a header of the previous response. How can I read the headers of the previous response, so I can extract the value to send?
Maybe better, more simple: How can I read the headers which come with a response?

Remove response header in grails

How can I remove a Header from response in grails. I have a filter which filters requests and in case response contains a specific header I want to remove it is this possible?
Thanks,
It looks like the only way to do this is to have your servlet filter wrap the response with an implementation of HttpServletResponseWrapper that filters out the header you want to remove. So you're not physically removing the header, but when the response is generated only the headers that your response wrapper returns will be included in the HTTP response.
I've not tried this, so if it does work, please let me know!

How to POST JSON in body for functional tests in Symfony 1.4

I'm writing some functional tests for a POST API endpoint. I've reviewed the documentation and can't find a way to add content to the POST body. The post method for sfBrowser:
post('some url',array('x'=>'y'))
Only creates POST parameters (in this case x=y). Is there anyway of adding content to the post body using sfBrowser?
From what I have found here, here and here, the POST format takes parameter:value format, so you can send your JSON with some code like:
post('some url', array('json_data' => json_encode($toJson))
and then decode in your action with
$jsonObj = json_decode($request->getParameter('json_data'));
but you need to associate your JSON data with a parameter name in your POST to retrieve it on the server side.
As a side note, after looking at the Symfony code, the parameters are given straight to $_POST except for CSRF, which is tweaked.

Cross-domain ajax post with JSON data going to Rails controller as HTML

I'm making a cross-domain POST request and have set up headers in Rails 3.2 to accept the request appropriately - both the OPTIONS and POST request are received by the controller correctly.
The problem I'm finding is that Rails controller is receiving the JSON data as HTML. Why is this? How can I force the controller to treat it as JSON? (doing this from the client-side would be preferable)
If this is unclear let me know which messages/code I ought to post for better assistance. Thanks
You could try adding the JSON extension to the URL that you're making a request to, i.e. https://your_domain.com/your_url.json, which should force the JSON format.

Resources