Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39396 > unrolled thread
| Started by | "C.D. Altenburg, Ph.D," <cdalten@gmail.com> |
|---|---|
| First post | 2020-03-16 07:47 -0700 |
| Last post | 2020-03-17 15:11 +0100 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
cross post. How do I get the http POST body? "C.D. Altenburg, Ph.D," <cdalten@gmail.com> - 2020-03-16 07:47 -0700
Re: cross post. How do I get the http POST body? Arne Vajhøj <arne@vajhoej.dk> - 2020-03-16 11:13 -0400
Re: cross post. How do I get the http POST body? "C.D. Altenburg, Ph.D," <cdalten@gmail.com> - 2020-03-17 04:52 -0700
Re: cross post. How do I get the http POST body? Arne Vajhøj <arne@vajhoej.dk> - 2020-03-17 10:05 -0400
Re: cross post. How do I get the http POST body? Joerg Meier <joergmmeier@arcor.de> - 2020-03-17 15:11 +0100
| From | "C.D. Altenburg, Ph.D," <cdalten@gmail.com> |
|---|---|
| Date | 2020-03-16 07:47 -0700 |
| Subject | cross post. How do I get the http POST body? |
| Message-ID | <16110cea-bf84-4823-ae22-adf692a1f499@googlegroups.com> |
I'm not going to post all 8000 lines to the engineering wonder....
The question is how do I get the post body in Java. Ie, the http body has the following format
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Type: application/json
Expires: -1
Vary: Accept-Encoding
Server: Microsoft-IIS/10.0
x-frame-options: DENY
Date: Mon, 16 Mar 2020 14:30:03 GMT
Content-Length: 1034
Strict-Transport-Security: max-age=31536000
X-CDN: Incapsula
X-Iinfo: 9-31663561-31663518 PNNy RT(1584369003228 523) q(0 0 0 -1) r(3 3) U6
{"SecuredPropertiesKey":"00000000-0000-0000-0000-000000000000","Success":true,"ErrorMessage":null,"Errors":[],"Warnings":[],"Informationals":[],"Result":{"EmployeeBalanceErrors":null,"EmployeeId":9414,"ExpiringTransactions":[],"Header":["Type","Accrued","Approved","Pending","Remaining","Exceeded","Unit"],"Totals":[{"BalanceId":3,"BalanceName":"PTO","UnitName":"Hours","BalancePeriodEnd":null,"BalancePeriodStart":"2020-01-01T00:00:00","Columns":[{"Header":"Type","Display":"PTO","Value":"PTO","ColumnType":1},{"Header":"Accrued","Display":"17.43737","Value":17.43737,"ColumnType":7},{"Header":"Approved","Display":"-3.50000","Value":-3.50000,"ColumnType":7},{"Header":"Pending","Display":"0.00000","Value":0.0,"ColumnType":7},{"Header":"Remaining","Display":"13.93737","Value":13.93737,"ColumnType":7},{"Header":"Exceeded","Display":"0.00000","Value":0.0,"ColumnType":7},{"Header":"Unit","Display":"Hours","Value":"Hours","ColumnType":6}],"IsGrantBased":false,"IsAccessRestricted":false,"SortOrder":-2147483648}],"Transactions":[]}}
I need all the data below X-Iinfo.
Here is my really long and ugly initial attempt in java...
private String downloadLoginPage(URL url) throws IOException {
Log.d(PRODUCTION_TAG, "===> " + url);
readJSON(url);
InputStream inputStream = null;
//HttpsURLConnection connection = null;
HttpURLConnection connection = null;
String result = null;
boolean redirect = false; //added on 9 - 25 - 2018
int code = 0; //added on 12 - 8 - 2018
try {
//connection = (HttpsURLConnection) url.openConnection();
connection = (HttpURLConnection) url.openConnection();
//HttpsURLConnection.setFollowRedirects(false);
//connection.setInstanceFollowRedirects(true);
//connection.setReadTimeout(9000); //3000ms
//connection.setConnectTimeout(9000); //3000ms
//connection.setRequestMethod("GET");
if (CookieManager.getInstance().getCookie(connection.getURL().toString()) != null) {
//String arr[] = CookieManager.getInstance().getCookie(connection.getURL().toString()).split(";");
//connection.setRequestProperty("Cookie", arr[1]);
//Log.i(PRODUCTION_TAG, "The client side cookie is: " + arr[1]);
}
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
//connection.setUseCaches(true);
//connection.addRequestProperty("Accept", "text/*");
//connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
//connection.addRequestProperty("Accept", "application/json");
//connection.setRequestProperty("Accept", "text/html, text/*");
//connection.addRequestProperty("Cache-Control", "no-cache");
//if (url.toString().contains("GetEmployeeBalanceDisplay")) {
connection.setRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate");
//}
//connection.setChunkedStreamingMode(0); //added on 9 - 12 - 2018
connection.connect();
Log.e(PRODUCTION_TAG, "THE RESPONSE HEADERS ARE: " + connection.getHeaderFields());
//Log.e(PRODUCTION_TAG, "THE RESPONSE CONTENT: " + connection.getContent().toString());
//int responsecode = connection.getResponseCode();
int responsecode = ((HttpURLConnection) connection).getResponseCode();
Log.e(PRODUCTION_TAG, "THE RESPONSE CODE IS: " + responsecode);
//int responsecode = 200;
if (responsecode != HttpsURLConnection.HTTP_OK) {
Log.e(PRODUCTION_TAG, "POSSIBLE 404? in downloadLogin()");
//connection.disconnect();
//redirect = true;
//return null;
throw new IOException("Http error code" + responsecode); //disabled in an attempt to debug
}
if ( responsecode == HttpsURLConnection.HTTP_MOVED_TEMP || responsecode == HttpsURLConnection.HTTP_MOVED_PERM) {
Log.e(PRODUCTION_TAG, "REDIRECT DETECTED");
//throw new IOException(" Http error code" + responsecode);
//return null;
throw new IOException("Redirect response code" + responsecode); //added on 10 - 2 - 2018
}
inputStream = connection.getInputStream();
Log.e(PRODUCTION_TAG, "THE RESPONSE MESSAGE IS: " +
readStream((InputStream) connection.getContent(), 5000));
if (inputStream != null) {
result = readStream(inputStream, 64000); //Lame way to emulate ping.
}
}
finally {
if (inputStream != null) {
inputStream.close();
}
if (connection != null) {
//connection.disconnect(); //why no else if??
}
}
return result;
}
//added on 8 - 16 - 2018.
private String readStream(InputStream stream, int offset) throws IOException{
InputStreamReader inputStreamReader = new InputStreamReader(stream, "UTF-8");
String result = null; //change from empty to null??! 10 - 4 - 2018
int maxLength = offset; //don't ask
//int maxLength = 100; //modified on 10 - 7 - 2018
char [] buffer = new char[maxLength];
int numChars = 0;
int readSize = 0;
/START REVISED CODE
//Possibly reading too large data stream. Hence why the insufficient resource error?
//Log.d(PRODUCTION_TAG, "STARTED TO READ STREAM"); //added on 10 - 4- 2018
while (numChars < maxLength && readSize != -1) {
numChars += readSize;;
inputStreamReader.read();
readSize = inputStreamReader.read(buffer, numChars, buffer.length - numChars);
}
if (numChars != -1 ) {
//Log.e(PRODUCTION_TAG, "INITIAL HTTP CONNECTION? " + numChars);
numChars = Math.min(numChars, maxLength);
result = new String(buffer, 0, numChars);
}
//Log.e(PRODUCTION_TAG, "===> " + result);
return result;
//return output; //close stream??
}
But all this yields is what appears to be the input form?
03-16 07:21:15.415 5938-5970/com.example.cd.workreminder E/LG_WORK_WEB:: THE RESPONSE MESSAGE IS:
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=10; IE=9; IE=8; IE=EDGE" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>
Dayforce
</title><link rel="shortcut icon" href="Content/Common/images/favicon.ico" /><link rel="apple-touch-icon" sizes="180x180" href="Content/Common/images/apple-touch-icon.png" /><link rel="mask-icon" href="Content/Common/images/safari-pinned-tab.svg" color="#3067db" /><link rel="manifest" href="Content/Common/images/manifest.webmanifest" /><meta name="theme-color" content="#ffffff" /><meta name="msapplication-square70x70logo" content="Content/Common/images/mstile-70x70.png" /><meta name="msapplication-square150x150logo" content="Content/Common/images/mstile-150x150.png" /><meta name="msapplication-wide310x150logo" content="Content/Common/images/mstile-310x150.png" /><meta name="msapplication-square310x310logo" content="Content/Common/images/mstile-310x310.png" /><meta name="msapplication-TileColor" content="#ffffff" /><link id="styles" rel="stylesheet" href="/MyDayforce/Content/Common/styles/rebrandedCss?v=nwLz1BN8ZUfRwzR_Cq1k8qgVoiBwHNkZkQYcDHpSaok1" />
<script type="text/javascript" src="https://static.dayforcehcm.comlibraries/jquery/3.4.1/jquery.min.js"></script><script type="text/javascript" src="/MyDayforce/Scripts/Libs/bootstrap-modal.js"></script></head>
<body>
<form method="post" action="./MyDayforce.aspx" id="duo_form">
<input type="hidden" name="__VIEWSTAT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ydLw4MmP9goAqt3h1qhseICdfON8cK7ZcMKDSdM8zsTEAbTTb3g1Ueo7b4H7Yd0zXhT39I+iC6fg06cA9o/gJYe1QmYCiNvew6nNOc+XgvKDkHAvYCTEnV+fvVa+rhWakI6MfpajrBOObPY5nEFq2pPeRzekFmWVXktP0z1Pc8l/osGrGTWPIcddw/Ktwjn+0ZOa4MT/F98VKJtOUbtMwXha2AdryqMjqH8jbbt873C/RHmbLxJO/8pshLRN99R4pbQ7TnDaOB1VG+xB07DSJU6cDH8/RFFG5gnkgUlI3MrMCnaJGsnQbtXiPLoukzCNPiVugEczp2iL7zW7
03-16 07:23:27.791 5938-5970/com.example.cd.workreminder E/LG_WORK_WEB:: THE RESPONSE MESSAGE IS:
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=10; IE=9; IE=8; IE=EDGE" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2020-03-16 11:13 -0400 |
| Message-ID | <r4o525$av0$1@gioia.aioe.org> |
| In reply to | #39396 |
On 3/16/2020 10:47 AM, C.D. Altenburg, Ph.D, wrote:
> The question is how do I get the post body in Java. Ie, the http body has the following format
>
> HTTP/1.1 200 OK
> Cache-Control: no-cache, no-store, must-revalidate
> Pragma: no-cache
> Content-Type: application/json
> Expires: -1
> Vary: Accept-Encoding
> Server: Microsoft-IIS/10.0
> x-frame-options: DENY
> Date: Mon, 16 Mar 2020 14:30:03 GMT
> Content-Length: 1034
> Strict-Transport-Security: max-age=31536000
> X-CDN: Incapsula
> X-Iinfo: 9-31663561-31663518 PNNy RT(1584369003228 523) q(0 0 0 -1) r(3 3) U6
>
> {"SecuredPropertiesKey":"00000000-0000-0000-0000-000000000000","Success":true,"ErrorMessage":null,"Errors":[],"Warnings":[],"Informationals":[],"Result":{"EmployeeBalanceErrors":null,"EmployeeId":9414,"ExpiringTransactions":[],"Header":["Type","Accrued","Approved","Pending","Remaining","Exceeded","Unit"],"Totals":[{"BalanceId":3,"BalanceName":"PTO","UnitName":"Hours","BalancePeriodEnd":null,"BalancePeriodStart":"2020-01-01T00:00:00","Columns":[{"Header":"Type","Display":"PTO","Value":"PTO","ColumnType":1},{"Header":"Accrued","Display":"17.43737","Value":17.43737,"ColumnType":7},{"Header":"Approved","Display":"-3.50000","Value":-3.50000,"ColumnType":7},{"Header":"Pending","Display":"0.00000","Value":0.0,"ColumnType":7},{"Header":"Remaining","Display":"13.93737","Value":13.93737,"ColumnType":7},{"Header":"Exceeded","Display":"0.00000","Value":0.0,"ColumnType":7},{"Header":"Unit","Display":"Hours","Value":"Hours","ColumnType":6}],"IsGrantBased":false,"IsAccessRestricted":false,"SortOrder":-2147483648}],"Transactions":[]}}
> private String downloadLoginPage(URL url) throws IOException {
> connection = (HttpURLConnection) url.openConnection();
> connection.setDoInput(true);
> connection.setRequestMethod("POST");
> connection.setRequestProperty("Content-Type",
> "application/x-www-form-urlencoded");
> connection.connect();
> inputStream = connection.getInputStream();
> if (inputStream != null) {
> result = readStream(inputStream, 64000); //Lame way to emulate ping.
> }
> 03-16 07:21:15.415 5938-5970/com.example.cd.workreminder E/LG_WORK_WEB:: THE RESPONSE MESSAGE IS:
> <!DOCTYPE html>
> <html>
> <head><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=10; IE=9; IE=8; IE=EDGE" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>
> Dayforce
> </title><link rel="shortcut icon" href="Content/Common/images/favicon.ico" /><link rel="apple-touch-icon" sizes="180x180" href="Content/Common/images/apple-touch-icon.png" /><link rel="mask-icon" href="Content/Common/images/safari-pinned-tab.svg" color="#3067db" /><link rel="manifest" href="Content/Common/images/manifest.webmanifest" /><meta name="theme-color" content="#ffffff" /><meta name="msapplication-square70x70logo" content="Content/Common/images/mstile-70x70.png" /><meta name="msapplication-square150x150logo" content="Content/Common/images/mstile-150x150.png" /><meta name="msapplication-wide310x150logo" content="Content/Common/images/mstile-310x150.png" /><meta name="msapplication-square310x310logo" content="Content/Common/images/mstile-310x310.png" /><meta name="msapplication-TileColor" content="#ffffff" /><link id="styles" rel="stylesheet" href="/MyDayforce/Content/Common/styles/rebrandedCss?v=nwLz1BN8ZUfRwzR_Cq1k8qgVoiBwHNkZkQYcDHpSaok1" />
> <script type="text/javascript" src="https://static.dayforcehcm.comlibraries/jquery/3.4.1/jquery.min.js"></script><script type="text/javascript" src="/MyDayforce/Scripts/Libs/bootstrap-modal.js"></script></head>
> <body>
>
> <form method="post" action="./MyDayforce.aspx" id="duo_form">
> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="7x5HGGKLqVDLU6TCIkiSRMEWoO4J2qwN+193zs+43Q5HQ9Hl4tu/iXcDcqTV6T3Fdr9qnukmnuTXhqk2Rg+4+QB5aO4t9cLysPlDGFju6JyZMD8ecI2yF9Z5Fz3ldHCfFhVSNN0xQ/b4WALW60KFmY29rciEmFa9eILUwGdpmTutwsYulPEYMYBSwTlV6jMB2UNp/GxviItHttY1iqhhyKUfT0GAcBaRPdSsojNOqPI2YQ7ElIUAnHa3rMQ2cNR1+s2ur+ULKTPw8e+4tEa8/4ROwBv0ik3oxhh7p65WplQ488aF8oCfTvJJ2Weq7AGJCSt1zs7Ehv6ElOPJjD9gI1b7ij1m83byVzQkgDAv+tkqV3xhqxUgX+HZtpWjKcMOATmoPFjr9L9UtliBhLzWXBfDlj3PuxS++qz+uOgNhcXWlBvhf5Y7CJxjxop+Gbss22i9FaCLu38tfG65xe2TB0dHfwyRJ/ax+rcJqG2Pf1oSkpxoQEn+Y+vVsvxNp/WifsZ7MpTFi09Zrp87q2AqON/rEufWwG5SiVymMTHSVSjzsqtmftKE0rTtsHIOZbZF7Vk/29pFSuimLLQfprvShc+noU9Gsd+Ttrg2zqD8my9ASPY4bajqgCgtPyrddKXxc3plVye2jlRM3c9TtRm8RGTzzHaZKnjBxFdHH965G7WFWg7hHptEcGr6h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ZTjb8nhA3pVlnOYPK3RpgiVWoOVhbMm1TO5BQhReizKvYZYgdOagARhS2pGEQNwlrKq3wqeHwS/UmglCq5wZU7ZshUJO1Dt1tgPbhStZ0QXHqbVLh4/Pndh5doPDCQe6YQ9EJuqKHP95dQs73mTDIVBUOrvfxIhVTugEoHoV2nG59IhIYPd2bwyiC1BueJc3dDQ1Ug8t9OiJV7VrOLhiPpO98qVVT82xPA1JgDUwHOG1lSd7mQlQv+2ZB2NTxAd4EIgRWslT3LeIrir4j/4lb/7/XzCiY8pXId0sQpNxO/7d2/yTWafQzvcw+walicW8E3mZPyySry2aNMfGVDu+T72qB78jiLt/BmQDBydLw4MmP9goAqt3h1qhseICdfON8cK7ZcMKDSdM8zsTEAbTTb3g1Ueo7b4H7Yd0zXhT39I+iC6fg06cA9o/gJYe1QmYCiNvew6nNOc+XgvKDkHAvYCTEnV+fvVa+rhWakI6MfpajrBOObPY5nEFq2pPeRzekFmWVXktP0z1Pc8l/osGrGTWPIcddw/Ktwjn+0ZOa4MT/F98VKJtOUbtMwXha2AdryqMjqH8jbbt873C/RHmbLxJO/8pshLRN99R4pbQ7TnDaOB1VG+xB07DSJU6cDH8/RFFG5gnkgUlI3MrMCnaJGsnQbtXiPLoukzCNPiVugEczp2iL7zW7
> 03-16 07:23:27.791 5938-5970/com.example.cd.workreminder E/LG_WORK_WEB:: THE RESPONSE MESSAGE IS:
The basic usage of HttpURLConnection.
Most people prefer to use Apache HttpClient (or if you are at
Java 11 then the new builtin HttpClient).
But all the above seems a bit mixed up.
It seem like:
* you want to call a web service and get some JSON data back
* you actually call a login page
What do you want to do?
Web service call should be pretty straight forward.
Login is usually also simple, but not for ASP.NET web forms, which
it looks like you are trying to access.
Arne
[toc] | [prev] | [next] | [standalone]
| From | "C.D. Altenburg, Ph.D," <cdalten@gmail.com> |
|---|---|
| Date | 2020-03-17 04:52 -0700 |
| Message-ID | <c62ad26e-4dad-4ba9-b3ba-0f3cc2f06287@googlegroups.com> |
| In reply to | #39397 |
On Monday, March 16, 2020 at 8:13:22 AM UTC-7, Arne Vajhøj wrote:
> On 3/16/2020 10:47 AM, C.D. Altenburg, Ph.D, wrote:
> > The question is how do I get the post body in Java. Ie, the http body has the following format
> >
> > HTTP/1.1 200 OK
> > Cache-Control: no-cache, no-store, must-revalidate
> > Pragma: no-cache
> > Content-Type: application/json
> > Expires: -1
> > Vary: Accept-Encoding
> > Server: Microsoft-IIS/10.0
> > x-frame-options: DENY
> > Date: Mon, 16 Mar 2020 14:30:03 GMT
> > Content-Length: 1034
> > Strict-Transport-Security: max-age=31536000
> > X-CDN: Incapsula
> > X-Iinfo: 9-31663561-31663518 PNNy RT(1584369003228 523) q(0 0 0 -1) r(3 3) U6
> >
> > {"SecuredPropertiesKey":"00000000-0000-0000-0000-000000000000","Success":true,"ErrorMessage":null,"Errors":[],"Warnings":[],"Informationals":[],"Result":{"EmployeeBalanceErrors":null,"EmployeeId":9414,"ExpiringTransactions":[],"Header":["Type","Accrued","Approved","Pending","Remaining","Exceeded","Unit"],"Totals":[{"BalanceId":3,"BalanceName":"PTO","UnitName":"Hours","BalancePeriodEnd":null,"BalancePeriodStart":"2020-01-01T00:00:00","Columns":[{"Header":"Type","Display":"PTO","Value":"PTO","ColumnType":1},{"Header":"Accrued","Display":"17.43737","Value":17.43737,"ColumnType":7},{"Header":"Approved","Display":"-3.50000","Value":-3.50000,"ColumnType":7},{"Header":"Pending","Display":"0.00000","Value":0.0,"ColumnType":7},{"Header":"Remaining","Display":"13.93737","Value":13.93737,"ColumnType":7},{"Header":"Exceeded","Display":"0.00000","Value":0.0,"ColumnType":7},{"Header":"Unit","Display":"Hours","Value":"Hours","ColumnType":6}],"IsGrantBased":false,"IsAccessRestricted":false,"SortOrder":-2147483648}],"Transactions":[]}}
>
> > private String downloadLoginPage(URL url) throws IOException {
>
> > connection = (HttpURLConnection) url.openConnection();
>
> > connection.setDoInput(true);
> > connection.setRequestMethod("POST");
> > connection.setRequestProperty("Content-Type",
> > "application/x-www-form-urlencoded");
>
> > connection.connect();
>
> > inputStream = connection.getInputStream();
>
> > if (inputStream != null) {
> > result = readStream(inputStream, 64000); //Lame way to emulate ping.
> > }
>
> > 03-16 07:21:15.415 5938-5970/com.example.cd.workreminder E/LG_WORK_WEB:: THE RESPONSE MESSAGE IS:
> > <!DOCTYPE html>
> > <html>
> > <head><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=10; IE=9; IE=8; IE=EDGE" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>
> > Dayforce
> > </title><link rel="shortcut icon" href="Content/Common/images/favicon.ico" /><link rel="apple-touch-icon" sizes="180x180" href="Content/Common/images/apple-touch-icon.png" /><link rel="mask-icon" href="Content/Common/images/safari-pinned-tab.svg" color="#3067db" /><link rel="manifest" href="Content/Common/images/manifest.webmanifest" /><meta name="theme-color" content="#ffffff" /><meta name="msapplication-square70x70logo" content="Content/Common/images/mstile-70x70.png" /><meta name="msapplication-square150x150logo" content="Content/Common/images/mstile-150x150.png" /><meta name="msapplication-wide310x150logo" content="Content/Common/images/mstile-310x150.png" /><meta name="msapplication-square310x310logo" content="Content/Common/images/mstile-310x310.png" /><meta name="msapplication-TileColor" content="#ffffff" /><link id="styles" rel="stylesheet" href="/MyDayforce/Content/Common/styles/rebrandedCss?v=nwLz1BN8ZUfRwzR_Cq1k8qgVoiBwHNkZkQYcDHpSaok1" />
> > <script type="text/javascript" src="https://static.dayforcehcm.comlibraries/jquery/3.4.1/jquery.min.js"></script><script type="text/javascript" src="/MyDayforce/Scripts/Libs/bootstrap-modal.js"></script></head>
> > <body>
> >
> > <form method="post" action="./MyDayforce.aspx" id="duo_form">
> > <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="7x5HGGKLqVDLU6TCIkiSRMEWoO4J2qwN+193zs+43Q5HQ9Hl4tu/iXcDcqTV6T3Fdr9qnukmnuTXhqk2Rg+4+QB5aO4t9cLysPlDGFju6JyZMD8ecI2yF9Z5Fz3ldHCfFhVSNN0xQ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0z1Pc8l/osGrGTWPIcddw/Ktwjn+0ZOa4MT/F98VKJtOUbtMwXha2AdryqMjqH8jbbt873C/RHmbLxJO/8pshLRN99R4pbQ7TnDaOB1VG+xB07DSJU6cDH8/RFFG5gnkgUlI3MrMCnaJGsnQbtXiPLoukzCNPiVugEczp2iL7zW7
> > 03-16 07:23:27.791 5938-5970/com.example.cd.workreminder E/LG_WORK_WEB:: THE RESPONSE MESSAGE IS:
>
> The basic usage of HttpURLConnection.
>
> Most people prefer to use Apache HttpClient (or if you are at
> Java 11 then the new builtin HttpClient).
>
> But all the above seems a bit mixed up.
>
> It seem like:
> * you want to call a web service and get some JSON data back
> * you actually call a login page
>
> What do you want to do?
>
I just want to call a web service and get some JSON data back. And I don't use HttpClient because it's not supported on the Java platform that I use.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2020-03-17 10:05 -0400 |
| Message-ID | <r4qlft$1fag$1@gioia.aioe.org> |
| In reply to | #39398 |
On 3/17/2020 7:52 AM, C.D. Altenburg, Ph.D, wrote: > On Monday, March 16, 2020 at 8:13:22 AM UTC-7, Arne Vajhøj wrote: >> On 3/16/2020 10:47 AM, C.D. Altenburg, Ph.D, wrote: >>> The question is how do I get the post body in Java. Ie, the http body has the following format >> The basic usage of HttpURLConnection. >> >> Most people prefer to use Apache HttpClient (or if you are at >> Java 11 then the new builtin HttpClient). >> >> But all the above seems a bit mixed up. >> >> It seem like: >> * you want to call a web service and get some JSON data back >> * you actually call a login page >> >> What do you want to do? >> > I just want to call a web service and get some JSON data back. And I don't use HttpClient because it's not supported on the Java platform that I use. Apache HttpClient is just a jar file - it should work on any Java compliant platform. If you are developing for Android it may be a bit messier - Android ship with an old version of Apache HttpClient, but you can add a special Android version of newer version if you need to. But HttpUrlConnection should also be able to do the job. You set method to POST you write request body to getOutputStream() and you read response body from getInputStream(). Arne
[toc] | [prev] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2020-03-17 15:11 +0100 |
| Message-ID | <2maeu666rt7l.16b4bdvgissk7.dlg@40tude.net> |
| In reply to | #39398 |
On Tue, 17 Mar 2020 04:52:39 -0700 (PDT), C.D. Altenburg, Ph.D, wrote: > I just want to call a web service and get some JSON data back. And I > don't use HttpClient because it's not supported on the Java platform > that I use. Then I very much recommend Retrofit. That is literally the exact use case it's made for. <https://square.github.io/retrofit/> Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web