Sunday, 15 March 2015

Java HttpClient get response from Post method -



Java HttpClient get response from Post method -

i new httpclient , i'm trying prices of players in fifa ultimate team web app.

using developer tools, managed find post method yielding prices of player.

searching specific player gives next url request. https://utas.s2.fut.ea.com/ut/game/fifa15/transfermarket?maskeddefid=20801&start=0&num=16&type=player

when i'm viewing response of method, can see player prices on market in developer tools.

so tried code in java prices, output nil response given in developer tools.

this code:

httpclient client = new defaulthttpclient(); string url = "https://utas.s2.fut.ea.com/ut/game/fifa15/transfermarket?maskeddefid=20801&start=0&num=16&type=player"; httppost loginpost = new httppost(url); loginpost.setheader("host", "utas.s2.fut.ea.com"); loginpost.setheader("connection", "keep-alive"); loginpost.setheader("content-lenght", "1"); loginpost.setheader("cache-control", "max-age=0"); loginpost.setheader("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); loginpost.setheader("origin", "https://www.easports.com"); loginpost.setheader("user-agent", "mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/37.0.2062.124 safari/537.36"); loginpost.setheader("content-type", "application/json"); loginpost.setheader("accept", "application/json"); loginpost.setheader("x-ut-sid", "23c19a93-32ac-4f52-9aab-21c6be112ede"); loginpost.setheader("x-ut-embed-error", "true"); loginpost.setheader("x-ut-phishing-token", "8649502695209937021"); loginpost.setheader("x-http-method-override", "get"); loginpost.setheader("referer", "https://www.easports.com/iframe/fut15/bundles/futweb/web/flash/fifaultimateteam.swf?cl=144469"); loginpost.setheader("accept-encoding", "gzip,deflate"); loginpost.setheader("accept-language", "nl-nl,nl;q=0.8,en-us;q=0.6,en;q=0.4"); loginpost.setheader("cookie", "cem-rememberlogin=mrllf4ua9qjaz1j1va8yrhwlh9jfealsccy1q3ja7wrewecjnf3h348jrrptnr3qxnhx-ykv6th3hwgepqgexdup2vmfeiwkayskhymujuyhf_fsou-fiv7ur2xvypqvo1kep_do0llaj5ztv1i8pawera57lpkmwxy5kzodnrtgbbpbbv2bjovplglpufwmbodmxelctqga7s2-nm3iczc0jqq2gmtdckj48vhstl3x3beut3ltfnvfet8elfif; path=/"); list <namevaluepair> nvps = new arraylist <namevaluepair>(); nvps.add(new basicnamevaluepair("maskeddefid", "20801")); nvps.add(new basicnamevaluepair("num", "16")); nvps.add(new basicnamevaluepair("start", "0")); nvps.add(new basicnamevaluepair("type", "player")); loginpost.setentity(new urlencodedformentity(nvps)); httpresponse response = client.execute(loginpost); httpentity entity = response.getentity(); string content = entityutils.tostring(entity); system.out.println(content);

this response developer tools showing , need:

{"auctioninfo":[{"itemdata":{"id":164674417976,"timestamp":1412181858,"itemtype":"player","pile":5,"resourceid":1929400641,"rating":93,"leagueid":0, etc}]}}

this response: ?[][][][][][][][]?v?m-.nlou??+???q*jm,??s?rj?(?,jmq([]?[]g[]et???s??l[][]k[]??[]?6[][][] [] stands unknown character (square)

so question is: how adjust code such response of requested url? help appreciated

edit: had delete 'setted' headers: 'setted' headers still need:

loginpost.setheader("host", "utas.s2.fut.ea.com"); loginpost.setheader("user-agent", "mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/37.0.2062.124 safari/537.36"); loginpost.setheader("x-ut-sid", "23c19a93-32ac-4f52-9aab-21c6be112ede"); loginpost.setheader("x-ut-embed-error", "true"); loginpost.setheader("x-ut-phishing-token", "8649502695209937021"); loginpost.setheader("x-http-method-override", "get");

but here, values of "x-ut-sid" , "x-ut-phishing-token" not correct, not actual values (since copied them previous session). how should prepare code in order actual value?

thanks in advance

is there documentation? maybe have set manually encoding, like:

loginpost.setheader("content-type", "application/json; charset=utf-8");

maybe alter "utf-8" other charset (like 'iso-8859-1')

java http-post apache-httpclient-4.x

No comments:

Post a Comment