我是Java的新手开发人员。第1步我已经完成了以下工作:
Java代码:
String url1 = "https://api4.liverail.com/login";
URL obj = new URL(url1);
HttpsURLConnection con1 = (HttpsURLConnection) obj.openConnection();
String urlParameters ="username=paania@gmail.com&password=d372a15b714bd250e";
con1.setDoOutput(true);
con1.setRequestMethod("POST");
DataOutputStream wr = new DataOutputStream(con1.getOutputStream());
wr.writeBytes(urlParameters);
第2步:我想将令牌传递给REST API以获取一些信息,例如来自类别的列表,但是当我通过GET方法发送请求时,我得到XML的响应[CDATA[You need to be logged in]]
这是代码在Java中:
String url = "http://api4.liverail.com/advertising/category/list/?token="72938howdwoi";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
BufferedReader in = new BufferedReader(newInputStreamReader(con.getInputStream()));
in.close();
con.disconnect();
我不确定我在这里缺少什么。
有什么建议吗?
答案 0 :(得分:0)
刚刚更改了url
以获取数据请求:
String url = "http://api4.liverail.com/advertising/category/list/?token=72938howdwoi";