I'm using Java HttpURLConnection to send a POST request to https://www.arcgis.com/sharing/generateToken with the parameters username, password, f, expiration, referer.
I need to get back the JSON response to extract the Token and store in my object, but the result I get seemingly is an HTML Page.
This is what I' sing, I simplified the code to keep my question clean
DataOutputStream wr = new DataOutputStream(httpConnection.getOutputStream());
wr.write(bytesArray);
wr.flush();
wr.close();
InputStream in = httpConnection.getInputStream();
Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
StringBuilder content = new StringBuilder();
char[] buffer = new char[5000];
int n;
while ( ( n = reader.read(buffer)) != -1 ) {
content.append(buffer, 0, n);
}
reader.close();
return content.toString();
Initial Params string: username=<correct username>&passowrd=<correct password>&f=json&expiration=60&referer=http%3Aww.arcgis.com
Data Bytes: [B@7506e922Sending POST request to URL : https://www.arcgis.com/sharing/generateToken
This is the response I get back.
Status Code:200
JSON Response Excpected: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>ArcGIS Portal Directory</title><link href="https://community.esri.com/sharing/files/gw.css" rel="stylesheet" type="text/css"/></head><body><br/><div class="gwDiv"><table class="navTable" width="100%"><tr><td class="breadcrumbs">ArcGIS Portal Directory</td></tr></table><tr valign="top"><br/><br/><b><a href="http://resources.arcgis.com/en/help/arcgis-rest-api/" >API Reference</a></b></tr></table></div></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>ArcGIS Portal Directory</title><link href="https://community.esri.com/sharing/files/gw.css" rel="stylesheet" type="text/css"/></head><body><br/><div class="gwDiv"><table class="navTable" width="100%"><tr><td class="breadcrumbs">ArcGIS Portal Directory</td></tr></table><tr valign="top"><br/><br/><b><a href="http://resources.arcgis.com/en/help/arcgis-rest-api/" >API Reference</a></b></tr></table></div></body></html>
Process finished with exit code 0
How do I get the JSON so that I can store the token in an object in Java Christophe SCILLIERI DevSummit Conference
Help please!
I believe the request should go to: https://www.arcgis.com/sharing/rest/generateToken (word "rest" between sharing and generateToken).
Actually this one https://www.arcgis.com/sharing/generateToken worked okay , maybe they are replaceable.
The things I changed is on
wr.writebytes(stringParams);