HTTP Response logging if using Ion - android

We can set logging if we use Ion to make HTTP connection to server as below
Ion.getDefault(getContext()).configure().setLogging("MyLogs", Log.DEBUG);
But we can't see the HTTP response from server from log that generated.
How to see HTTP response ?

Ion does not put the response body into the logs, as the body may be enormous, binary, etc.
If you want to log the body, do so yourself in the setCallback.

Related

Okhttp multiple response handling for single request android

I have an android application and I am trying to make an http/2 call with okHttp version 3.13.1, in my case for one request I will be receiving two responses sequentially from the server, but with the okHttp client I am getting only one response and if I try to send the request using curl command I am receiving two responses sequentially from the server.
Is there a way to handle multiple responses for a single http/2 request in android?
I tried various ways, but no luck:( Would be more than happy, if anyone could provide your inputs.
Thanks for your help and time in advance!!!
I am basically sending a get request from my android application using okHttp client to a server which supports http/2, so expecting to receive 2 different response for that single request in a timely manner.i.e the second response will be sent from the server after 5 seconds gap of receiving the first response.
Below is my response :
First response
event:initialize
{"session_id":"df313001-6461-431c-bcc1-7cb931bda4f5","deviceId":"YL0012345678"}
Second response
event:voice_response
data:{"intents":[{"version":0,"intent":"telstra_intent_voice","params":{"voiceResponse":{"displayText":"Launching now","vuiFileName":"E03.01.P2.V01.E.wav"},"action":{"ecp":"/launch-install/71361"}}}],"deviceId":"YL0012345678","channelId":"269671"}
But, in my case once I receive the first response the client is no longer listing to the server. When I receive the first response, in my log I see :
com.example.okhttp3 D/OkHttp: <-- END HTTP (166-byte body),
so not receiving the second response.
Appreciate your help!
I found a workaround. You can send the response as multipart data. Then encapsulate all your responses into the multipart data seperated by 'boundary'. The multipart data will not end until you send the 'end mark'(0). Then the client side could decode all the responses one by one simultaneously when the server sending the multipart data.
The multipart data will looks like this:
--boundary
response_1
--boundary
response_2
...
--boundary--
0
there is also a demo here.

Postman can't send post request to server and server detecting it as get request instead of post

Having issue in postman can't send post request to the server.
So I have
#GetMapping("/{id}")
public blablabla (#PathVariable long id )
#PostMapping("/scan")
public blablablabla(){}
Somehow when I send post request for /scan via postman it returns
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long';
nested exception is java.lang.NumberFormatException: For input string: \"scan\
But it works fine in my android application.
Is this postman issue?
Thank you
I've got the answer..
In postman, I send http request to my https server.
So it's redirecting it making it a GET request instead of my POST request.

HTTP request Post to a Server where HTTP body is a JSON dictionary

I have a server I need to POST an http request to. The server is located at http://ec2-54-187-236-58.us-west-2.compute.amazonaws.com
I need to execute a POST /ios/search
I'm given that the HTTP body is a JSON dictionary but I cannot connect to the server itself. Nor am I able to see the JSON object in javascript when I enter the server url in a browser. I am using gson library in android to help me execute the http client request, but am getting the
IOException: Connection to http://ec2-54-187-236-58.us-west-2.compute.amazonaws.com/ios/search refused
What am I missing? Or is there an issue with the server url?

OkHttp 2.0 Response (of a POST request) body string is an empty string

I'm switching to the new Request/Response implementation provied by OkHttp 2.0
I got no problem with GET request, I can easily read the response body string, instead I have a problem reading response body string from POST request.
Actually I make a POST request (request body is a JSON media type) to my server that is responding with 201 http status code and a JSON inside the response body.
The POST request go fine (server is saving data) but I cannot read the body string from my android app. The response body string is an empty string while the response http status code is correctly 201.
I'm reading the response body like in the GET request with response.body().string().
Should I do something particular on client/server side to read correctly the response body string?
It seems that the problem was server side.
When I specified from server side that the response content_type was "application/json" and status=200 (I was using 201) the response.body().string() from OkHttp returned the real response JSON instead of the empty string.

Http requests from android app to django server

I am able to log into the django server using an Http Post request, but when I go to see if the user is authenticated immediately after I am getting a HTTP/1.1 401 UNAUTHORIZED response.
I am using the same DefaultHttpClient for both the post and the get request by means of a static member.
I have already attempted adding the sessionid cookie from the POST request to the GET request as a header.
Is there anything I am missing?

Categories

Resources