http - Generating HttpRequest from specific IP in Java -


i using apache httpclient generating post request , submitting data. since remote application relays on ip address of user that's submitting data, want send post request user specified ip address.

how configure this?

public static void loginuser(string username, string password, string ip) throws exception{       try {             httpclient client = new defaulthttpclient();             httppost httppost = new httppost("http://login.myapp.com/");              // request parameters , other properties.             list<namevaluepair> params = new arraylist<namevaluepair>(2);             params.add(new basicnamevaluepair("username",username));             params.add(new basicnamevaluepair("password", password));             httppost.setentity(new urlencodedformentity(params, "utf-8"));              // execute , response.             httpresponse response = client.execute(httppost);             httpentity entity = response.getentity();              if (entity != null) {                 //etc....             }         } catch (exception e) {             e.printstacktrace();         }     } 

edit: avoid confusion,

i want include custom ip address in httprequest headers end application knows that, request [from app] came custom ip address not ip address application running

let's application running on server ip address "1.1.1.0". user executing loginuser method "test","test","199.199.199.0". http request application destination url should go sent "199.199.199.0"

op writes:

i want include custom ip address in httprequest headers end application knows request [from app] came custom ip address not ip address application running
...
let's opened google.co.in, google server knows request came ip address. if use httpclient in apache, how configure ip address when google server reads, treat request came ip address

you can't.

(this 4th interpretation wrote in original answer below.)

the sender's ip address not sent http header. it's sent in field in ip protocol header. server obtains sender's ip address down low @ socket level, not obtain http information.

and no, not fake ip (it's called "spoofing") if wanted to. java not have native support raw sockets, cannot modify information @ ip level. if (or use jni or outbound packet filtering application or hardware), nature of tcp makes ip spoofing useless situation (responses sent fake ip, many other difficulties beyond scope of answer).

so, no, cannot trying do. either need special rules put in place administrators of server trying connect to, or need rethink design of application.

edit: other alternatives

i mentioned these in comments on question i'm including them here in answer completeness:

one possible solution, depending on security requirements, set vpn access users, users must establish vpn connection first, , run web application on internal server.

you have web server connected network via vpn , access internal login services directly through vpn link, web application running on wan link.


this original answer before op clarified requirements:

not clear asking answer possibilities can think of.

if mean want let user specify ip address of server sending post to, build url ip address:

httppost httppost = new httppost("http://" + ip + "/"); 

if mean want server based on user's ip address: user's ip address available on server side when server receives request, don't need send explicitly. how access information, server side, depends on server using.

if mean want user able specify ip address sent server, send send other parameters:

params.add(new basicnamevaluepair("whatever", ip)); 

if mean logging in system relies on user's ip address, server on behalf of remote user, , want pretend remote user log in succeeds: can't. system trying log has security measures in place prevent trying do. perhaps possible owners of system put in exception server's ip address; you'd have ask them.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -