0
我正在做一個網站的android應用程序。我真的是網絡上的新手,我不知道如何發送XMLHttpRequest並獲得它在Java中的響應。用Java發送XMLHttpRequest
有關請求的信息,我想做的事:
響應:
這是我的代碼:
Connection.Response resp = Jsoup.connect("https://eksisozluk.com/entry/" + entryId).cookies(loginCookies).method(Connection.Method.GET).execute();
String cookies = resp.cookies().toString().substring(1,resp.cookies().toString().length()-1).replace(",",";");
URL url = new URL("https://eksisozluk.com/entry/favla");
URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("cookies",cookies);
urlConnection.connect();
OutputStream outputStream = urlConnection.getOutputStream();
outputStream.write(("{\"entryId\": \"" + entryId + "\"}").getBytes("UTF-8"));
outputStream.flush();
InputStream inputStream = urlConnection.getInputStream();
java.util.Scanner s = new java.util.Scanner(inputStream).useDelimiter("\\A");
Log.d("Response",s.hasNext() ? s.next() : "");
我知道這是可能完全錯了,但我j烏斯特想告訴你我曾試圖做一些事情。