I have an apache server that gets POST requests from an Android device for further process.
First the user has to log in. Then the server returns a cookie that the app uses to detect if the credentials are valid. Then the user can send requests to the server.
Because the mobile device may experience 3G/4G network issues I check after sending every request the response code that the server returns. If the response code is not 200 I save the request data and try again after some time.
The strange part of this process is that sometimes (randomly) although I get 200 as response the server rejects the data get lost. Even stranger is that when I tried to read the log file.. (It's pretty big because the server hosts more than one projects) i saw that the server logged that responded with 302 instead of 200 that i get on my device...
I wrote a php script that returns 302 as response and I tested my Android application and runs fine. It detects that response is not 200 and saves the data correctly. I also tried to send data to the server without log in and I get 302 as it should.
So I suspect that the problem is on the server side. What can I do? I am trying to figure out what's wrong for about six months but it happens randomly and i cannot find the cause. Has anybody faced the same problem in the past?
Thanks a lot.
So, I finally found the bug. For some reason the session expired and I redirected back to the login page thats why 302 logged, and after the successful load of the login page I got 200. I forced apache client to prevent redirects and its fine now
Related
I am currently using the DefaultHttpClient to create an HTTP request to a rails server.
The network call is failing about 4% of the time with a SocketTimeoutException.
I have run Wireshark on my network traffic and discovered the following:
My successful call starts like this
And ends like this
The failed call starts like this:
And ends like this
Please note that the HTTP OK message that is sent to us from the server is missing from the end call, resulting in it timing out after about 15 seconds.
I am wondering if anybody has encountered this before or has any recommendations for debugging the Android Apache library or Apache rails to figure out why we are not receiving the HTTP OK message from the server.
I figured this out. The rails server and apache library were timing out if there were bad parameters in my post request. We were passing in a "_b" parameter, and for some unknown reason the server wouldn't like this and would time out the request. Removing the bad post parameter fixed the problem.
If anybody else is seeing timeouts like this, I recommend reviewing the POST parameters that are being passed in.
I have a ASP.NET website deployed to IIS with a couple of ashx that returns JSONs to be consumed by an Android application.
I have implemented an authentication logic using Basic Authentication.
The problem: When accessed from Android, the server response is a 400 Bad request. The httperr log file says "400 - Hostname -".
It works when I try it out on localhost from Android emulator
It works when accessing the ashx file on the server from a browser
It works when replicating the call in Fiddler
(If I use Fiddler with the Android Emulator, the Response will be -1 (and looking in Fiddler at the raw data sent, it seems to loose the host from the url) - but this is another issue so don't dwell on that, i just thought I would mention it...)
Turns out my problem (and solution) was the same as in this thread:
HTTP POST request with authorization on android
So I have a django development server that I want to be the backend for my android app. For the time being, its I am just running the development server on my local machine.
I've been able to successfully retrieve data from the server, but I am now trying to POST data to the server through a JSON object, however I keep getting error code 403 in response. The method in my views.py file doesn't even get called, it just automatically response with 403. Heres what the server response looks like in the terminal.
[28/Nov/2011 17:58:40] "POST /createUser/ HTTP/1.1" 403 2326
Here is the url in my urls.py
url(r'^createUser/$', 'mydb.views.createUser'),
But I am always getting this 403 error, does anyone know why?
Possibly also important:
when I remove django.contrib.auth and django.contrib.contenttypes from INSTALLED_APPS I get a different print out from the server in the terminal: (error code 500 instead)
[28/Nov/2011 17:32:31] "POST /createUser/ HTTP/1.1" 500 82471
So I am thinking there is some sort of permissions issue going on.
For a quick fix, try adding #csrf_exempt decorator to the view:
from django.views.decorators.csrf import csrf_exempt
#csrf_exempt
def createUser(request):
That said, for a back end API, definitely read up on CSRF
I read the following link about CSRF tokens: docs.djangoproject.com/en/dev/ref/contrib/csrf
Then I turned off middleware since I am just on the localhost for the time being.
In my android app i keep getting timeouts in the messages between the app and my server.
In an attempt to see if the problem is in the app or my server,
i want to try and Send an HTTP request from my app to
some other server i am sure is up and reliable and then see if i get timeouts.
Is there any server address i can check against?
Thanks in advance!
BTW : i am using a glass Fish servlet for my server
We've successfully sent a simple HTTP GET to google.com -- with a couple of fall-backs (I've also seen internic.org used) in the past, in similar cases.
I'm writing an HTTP client in Android that connects to glassfish on my localhost and sends some json information to the server.
I use:
UsernamePasswordCredentials cred =
new UsernamePasswordCredentials(SettingsHelper.mUser, SettingsHelper.mPwd);
client.getCredentialsProvider().setCredentials(AuthScope.ANY, cred);
for authontication, and making a put request.
The problem is sometimes, the client sends an unauthorized request before retrying and sending an authorized one, and on the second time, it pushes the json entity, before getting a proper response from the server (100 - continue). then, the server doesn't respond at all, and everything hangs.
i will note that sometimes it works.
Has anyone else experienced this problem? How might I resolve it?
finally managed to make it work with basic pre-emptive authontication.
example here