i want call api accepts raw data when send requests using jsoup.
my code looks this:
document res = jsoup.connect(url) .header("accept", "application/json") .header("x-requested-with", "xmlhttprequest") .data("name", "test", "room", "bedroom") .post();
but know above code not right passing raw data.
can tell me how can it?
you'd have use httpurlconnection
post raw data website, , fetch response string. example, post data:
httpurlconnection conn = new url("http://somesite.com/").openconnection(); string str = "some string goes here"; //use string our raw data byte[] outputinbytes = str.getbytes("utf-8"); //byte array raw data outputstream os = conn.getoutputstream(); os.write( outputinbytes );
getting response string:
bufferedreader in = new bufferedreader(new inputstreamreader(conn.getinputstream())); stringbuilder response = new stringbuilder(); string inputline; while ((inputline = in.readline()) != null) { response.append(inputline); } in.close(); conn.disconnect();
to parse jsoup:
document doc = jsoup.parse(response.tostring());
Comments
Post a Comment