Run http server proxy in android? - java

is it possible to create a mini HTTP server that acts as a proxy where i can recieve any requests from a webview and it will pass that request to my http proxy server running inside the app that can then view the raw contents of that request(http headers, bodies etc) and handle it from my own proxy?
I can see that the apahce libraries only contain objects that allow you to create requests and handle responses but not how i can create a mini http server.
Thanks

I don't understand the question fully so here's the question I am going to be answering.
Is it possible to create a HTTP server that allows me to view the source code of a web page.
The answer is: yes.
Since I don't really develop for Android phones, I'm only going to list out what you should do.
So first of all you want to accept a connection from a client. Then you might want to send it back a HTML page containing a form with a website URL field. If you set the method to POST, you will be able to make the URL of any length. Now your server needs to know how to receive the HTTP POST request. I don't really know the HTTP well enough to tell you how the request-response is encoded.

Related

How does browser handle http requests

Hi I have some problems trying to handle http requests on my own and show them on screen using webview
Using the
shouldInterceptRequest
function in WebViewClient
So far, things are fine. I handle the matter well and receive cookies from the response headers and send them again in the next request.
But I'm having problems processing post requests
As the server expects some information from me in the request body, such as the password, email, and some other parameters that differ from one site to another.
Now my problem is how do I know what parameters are required from the server, such as the browser, as the browser handles these requests with ease and dwarfs sending all the required parameters
I tried to monitor requests via DevTools in PC chrome and I saw what parameters are required to login in only one site
I managed to get these parameters with javascript via
wb.loadUrl("javascript:const formData = new FormData(document.querySelector('form')); for(var pair of formData.entries()){INTER.putForms(pair[0],pair[1]); }");
I made a javainterface and put in it a putforms function that receives the information and puts it in a hashmap
Now I have solved the problem in one site, what about the rest of the sites? This method is not easy at all, I have to know how the browser deals with these requests
Please Help

Simulate form post using http client in Android app?

So, I'm currently developing an app for a service which has a json-based (unfortunately) read only API. Retrieving content is no problem at all, however the only way to post content is using a form on their site which location is a PHP script. The service is open source so I know which fields the form expects, but whatever I send, it always results in a BAD REQUEST.
I captured the network traffic inside my browser and as far as I can see, the browser constructs a multipart form request, however when I copy the request and invoke it again using a REST client, a BAD REQUEST gets returned.
Is there a way to construct a http request in Android that simulates a form post?
If it's readonly I think you wouldn't be able to make requests with POST (it's assume for editing or adding things).
If you let me make you an advise, I recommend you using this project as a Library.
https://github.com/matessoftwaresolutions/AndroidHttpRestService
It makes you easy deal with apis, control network problems etc.
You can find a sample of use there.
You only have to:
Build your URL
Tell the component to execute in POST mode
Build your JSON
As I told you, I don't know even if it will work.
I hope it helps!!!

Servlets - Send Response Based on Session Only

I get a request from one client, I want to build a response and send it to two clients (one of which is the requester). The only piece of information I know about the other client is its session. Is there a way to construct a HttpResponse object using an HttpSession object?
Im not sure about what youre trying to accomplish, but you may want to contact the second client via "reversal ajax". You may want to take a look at Comet Programming
Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it. Wikipedia

jsonp referer url determine

I have a jquery plugin and I'm using jsonp for crossdomain call to a jsp file.
I want to strict the jsp return values only to specific websites in our database.
To achieve this I need to somehow get the ip or url of the website the jsonp call triggered and not the client/user ip. I've tried the referer value in the http header but this will not work with IE and I guess this is not the best solution either.
How can I securely now who is calling my jsp file with my plugin, from his website?
Thanks in advance.
The simplest answer would be to issue each website a unique key or other identifier that they include in their request. You parse this identifier and flex your response appropriately.
However with a request originating from the client browser, you would have to be careful and would have to evaluate what you mean by how "securely" you need the request to be handled. (since the untrusted client would be making the request it would be a simple task to harvest and reuse such an identifier)...
Referrer (if present) could be used as a double check, but as you pointed out, this is unreliable and coming from an untrusted client computer, this portion of the request could be faked as well.
If we could assume some server side processing by the website owners, you could have them implement a proxy for the jsonp call (which would ensure such a token would never fall into the hands of the browser)... but we'd have to know if such a safeguard would really be worth it or not :)

Webservices in BlackBerry

I am trying to make an application that will connect to a web service and call functions from it. I have worked on HTTP connections that will hit the server. This one will send me data. But can I hit a web service and call functions from it on Blackberry? I don't have such information yet haven't tried it.
So the question is, how to connect to a web service and call functions from it?
You won't be able to directly call functions on the server from the BB, so you'll have to define calls on the server where your app would provide the information needed for your server side script to perform the necessary operations.
As a simple example, maybe your app sends something to the server to a login URL with a payload that has the username and password. The server would then take over and perform all of the necessary validation and come back with a simple "authenticated" or "denied" response. Your app didn't actually do anything other than provide the information that would be needed for the server to do its magic.

Categories

Resources