java - HTTP GET request get HTML page code instead of expected json Response -


/here code/

<html><head><meta http-equiv="refresh" content="0; url=http://www.fifacoinservice.com/api/v1"></head><body></body></html> http/1.1 400 bad request server: pipeguard date: mon, 15 jun 2015 10:29:32 gmt content-type: text/html content-length: 605 connection: close  <!doctype html public "-//ietf//dtd html 2.0//en"> <html> <head><title>400 bad request</title></head> <body bgcolor="white"> <h1>400 bad request</h1> <p>your browser sent request server not understand. sorry inconvenience.<br/>     please report message , include following information us.<br/>     thank much!</p> <table>     <tr>         <td>url:</td>         <td>http://_</td>     </tr>     <tr>         <td>server:</td>         <td>5.254.102.236.r00t-services.net</td>     </tr>     <tr>         <td>date:</td>         <td>2015/06/15 10:29:32</td>     </tr> </table> <hr/>powered pipeguard</body> </html> 

here call

url url = new url("http://www.server.com/api/v1");             string query = "api_key=q5eicsks027cjut7qhzk&method";              //make connection             urlconnection urlc = url.openconnection();              //use post mode             urlc.setdooutput(true);             urlc.setallowuserinteraction(false);              //send query             printstream ps = new printstream(urlc.getoutputstream());             ps.print(query);             ps.close();              //get result             bufferedreader br = new bufferedreader(new inputstreamreader(urlc                 .getinputstream()));             string l = null;             while ((l=br.readline())!=null) {                 system.out.println(l);             }             br.close(); 

you need set accept header.

urlc.addrequestproperty("accept","application/json"); 

update

your server may not support application/json datatype. can check curl.

curl -x post  -h "accept: application/json" --data 'api_key=q5eicsks027cjut7qhzk&method' http://www.server.com/api/v1 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -