I'm using a PHP Web Services that I'm consuming on an Android application.
The Web Services inserts data on a database and returns information from it.
How I can parse the result of using that Web Service to avoid errors?
In Android, I execute the post request by this way:
HttpResponse response = httpclient.execute(httpost);
What should I do on the Web Service to process possible errors?
Thanks!
As eduyayo and Deutro said. You can check status code of your response
int statusCode = response.getStatusLine().getStatusCode();
List of Status codes - HttpStatus codes and handle exceptions accordingly.
On your Server you should return different StatusCodes for different ErrorMessages.
In your client you can check for the error StatusCodes and update your UI according to the error you get.
Related
An Android application sends a request to "https://google.com". How would i
fake the HTTP response without an actual network request, using Frida?
I am trying to teach myself reverse-engineering, but I can't figure out how to do this.
The best way of doing that is redirecting the request to an address that you control and then return there a user-controlled response.
You will then need to find which methods to instrument related to the HTTP request itself and return valid data to the app.
I have a HTTP GET which returns status 200 with some response. This response it is given as a result of redirecting.
If I introduce asyncHttpClient.setEnableRedirects(false); in my code, then redirection stops and it comes in failure with status 302. But in my application, this status 302 and response associated with it is what I need.
I am searching online and trying to figure out, but I am new to Java so not able to understand how to achieve this.
What I want is, when server returns status 302, I want to trigger onSuccess and capture response. Thanks.
If I'm getting right what do you need then you could implement your own AsyncHandlers to react with a different AsyncHandler.State for 302 status code. ( https://github.com/AsyncHttpClient/async-http-client#using-custom-asynchandlers) or while creating the client stop to follow redirects like this:
asyncHttpClient(config().setFollowRedirect(false))
(it might be different from the approach you mentioned above.)
P.S. I'm using 2.5.2 version of the asynchttpclient lib.
Some third party is sending an Http Post request whenever something changes in their DB (e.g. when a contact has been updated, they send the contactID and 'contact_updated'). I have build a socket listener that catches those requests and is able to parse the information. However, I just can't get it to work to send back a response with the status '200 - OK'. Thus, the server on the client side keeps on trying (four times or so) to re-send the request.
Is there any, simple way to just send the response status without the need of adding external libs etc.?
It should be enough to send the string HTTP/1.1 200 OK back in your socket-listener.
If you have troubles, you can check out this answer, it shows how to use a HttpServer in Java just via plain JavaSE features.
Use
response.setStatus(HttpServletResponse.SC_OK);
to set the status code in your response header.
You may also set the content type.
response.setContentType("text/html;charset=UTF-8");
I have a UI page developed using angular js and make a rest webservice call. If an exception is thrown by webservice will the control be returned to the UI with the error?
yes, it will be returned to the client. This is true even if the server timesouts.
But it might not be in a format as you expected. For example, you might have sent a json request and expecting a json response. But you might get an html response if the server has setup a simple html handler for error code. In this case your response parsing will fail. One common example is the authentication failure, which simply redirects you to html login page in many services.
So before parsing the result, check the status code. Check the service rest api docs and study the error handling semantics. Then parse the error accordingly.
I've been unable to make a "DELETE" request using the code below :
URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
URL posturl = new URL("http://www.example.com/comment?token=xxx");
HTTPResponse response = fetchService.fetch(new HTTPRequest(posturl, HTTPMethod.DELETE));
int responseCode = response.getResponseCode();
This is for Google Appengine. The 'DELETE' request is for the facebook graph API. The above code gives me a status code 400 - Bad Request.
This is for face4j an open source java library that I've built for the facebook graph API.
This isn't really an App Engine problem; it just means that the destination webserver wouldn't accept your request.
If you're actually trying to send a DELETE to example.com, that's your problem. If that's supposed to be a scrubbed URL, you've omitted the detail that would facilitate troubleshooting.