I have an established code base which successfully makes GET and POST requests to a server to download/upload data. We're looking to change the domain name and have set up a 301 HTTP redirect to go from the original domain to the new domain. When doing a GET request, it seems to automatically handle the redirect in the background and successfully retrieves the response. When I am sending a body via POST, however, it throws a java.net.ProtocolException: content-length promised xx bytes, but received 0.
Is there any way to ensure that the body is sent in the redirect request as well? Thanks for any help in advance!
Related
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.
I want to do a POST HTTP request to the serving to receive some cookies from the server. During this POST request I also need to send some data like login and password. I found a lot of solutions but nothing is working, everything that I found is deprecated.
So the question is: how can I make a HTTP POST request to receive form the server some cookies after?
I have an app that makes request to a wcf service. Usually I authenticate all of the requests using a hash value that is sent in the body of the request and then authenticated on the server. All most all of the request are sent via json and it is easy for me to add the hash value to the body of the request. The issue I am facing is that when I send a file stream I cannot add the hash to the body of the request so I am wondering how I can authenticate that the request came from my app and not from some where else. All suggestions are greatly appreciated.
Adding an authorization item in the header is a possible solution. So, if anyone is interested, read this and this.
I have 2 textboxes and a button how do I log into a website? If the user and password are wrong then it should give an error.
It depends on how the webserver is set up, but as a simple approach, you can make and HTTP POST request, and based on either the http code returned or a message you can tell the user success or fail.
For a code snippet on how to do a POST request you can look at
http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient.
You should also be doing this over HTTPS since you are sending a password.
You can use SOAP request for this purpose.
Send your soap request with user-name and password parameters.
In response, you will get the acknowledgment true of false, on basis of which you can show any user friendly message in your android login screen.
i'm sending an http request to the google reader api and getting an unusual response code. following the documentation, i've requested an auth code and included it in the header of every request. after performing the login, and getting an auth code, i tried accessing this url, which is part of the documentation:
http://www.google.com/reader/api/0/stream/items/contents
when i send the request, i get a 411 status code, which is supposed to mean "Length Required". the length, as i've found, is supposed to be the length, in octets, of the message body. there is no message body in this request. there is only a single header, the POST parameter i="item id" and the URL itself. i tried setting the "Content-Length" header to "0" and also to "-1" to no avail.
what's really interesting is that this same code worked fine before google changed their authorization procedure. it's apparent they've changed something else...
so my question is what EXACTLY would cause a 411 response code and how can i prevent it?
This error happens only with POST and PUT request types, as these two (sort of) expect to have a request body that includes the request parameters (plain textual as well as attachments).
However as the documentation suggests, this is largely an obsolete value, and realistically the web services should handle requests without relying on Content-Length.
So it's not the problem of a request sender, but it is (I would say) a bug on the service side.
Nevertheless, setting a Content-Length (mind the proper capitalisation) request header to 0 should be the workaround.