{"errorDescription":"Incorrect request","errorCode":1}
And this is the method code that produces the above error. (A Java whiz will recognize it as ripped-off code to POST to a form page, which is what it is ):
private static String HTTPPost(String ApiChoice, String params) {
String output;
int responseCode;
String urlString;
URL url;
URLConnection urlconnection;
HttpURLConnection connection;
DataOutputStream out;
BufferedReader in;
String whoops;
int i;
output = "Wrong crypto parameter!";
if(ApiChoice.equals("nxt")) {
urlString = NxtApiLoc + "/nxt";
}
else if(ApiChoice.equals("nhz")) {
urlString = HZApiLoc + "/nhz";
}
else return output;
// Might need to add an ? after /nxt and /nhz.
output = "";
try{
url = new URL(urlString);
urlconnection = url.openConnection();
connection = (HttpURLConnection)urlconnection;
connection.setRequestMethod("POST");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(params);
out.flush();
out.close();
responseCode = connection.getResponseCode();
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
output = in.readLine();
/*
Might want to try this approach:
StringBuffer fetcher = new StringBuffer();
while ((output = in.readLine()) != null) {
fetcher.append(inputLine);
}
in.close();
output = fetcher.toString();
*/
} catch(IOException ex) { output = "Failed"; };
return output;
}
Anyhoo, I'm not trying to turn this thread into Stack Exchange: I just clipboarded this code to show you what I'm trying to do.
If there's anyone here that has a method that successfully makes a POST request to the API, I'd be grateful if you could share how you did it. Thanks!
The NFD NSC Asset transfer tool used post requests:
https://bitbucket.org/NFDcoin/nfdcoin/src/98e60e67f1df0e073862c787fda7312f3eba85b1/src/java/nfd/util/NSCAssets/APIRequest.java?at=NFD-1.2.9#APIRequest.java-54
Example to use the sendRequest method.
https://bitbucket.org/NFDcoin/nfdcoin/src/98e60e67f1df0e073862c787fda7312f3eba85b1/src/java/nfd/util/NSCAssets/NSCAssetTransfer.java?at=NFD-1.2.9#NSCAssetTransfer.java-149
StringBuffer url = new StringBuffer();
url.append((isHttpsConnection ? "https" : "http"));
url.append("://localhost:");
url.append((isTestnet ? "9876" : Nxt.getIntProperty("nxt.apiServerPort")));
url.append("/nxt?requestType=transferAsset");
url.append("&secretPhrase=" + secret);
url.append("&comment=" + transferMessage.getMessage());
url.append("&recipient=" + Convert.toUnsignedLong(generatorAccount.getAccountId()));
url.append("&asset=" + NSC_ASSET_ID);
url.append("&quantityQNT=" + transferMessage.getQuantity());
url.append("&feeNQT=100000000&deadline=100");
StringBuffer buffer;
if (!isDryRun) {
buffer = APIRequest.sendRequest(url.toString());
} else {
buffer = new StringBuffer("mode --dry-run: sending of transactions is disabled");
}