3

I'm using Processing 2.0.2 and importing java's java.net,javax.net, and java.io classes.

I'm trying to send a JSONObject to "https://www.bitstamp.net/api/balance/".

The JSONObject contains login info. I create it with this function:

JSONObject BitstampLoginJSON() {
JSONObject loginJSON = new JSONObject();
loginJSON.setString("password", "mypassword");
loginJSON.setString("user", "username");  
return loginJSON;
}

I setup my connection successfully and then pass the connection to this function to send the request.

void SendBitstampBalanceRequestFromConnection(HttpsURLConnection givenCon) {
try {
givenCon.setDoOutput(true);
givenCon.setDoInput(true);    
givenCon.setRequestProperty("Content-Type", "application/json");  
givenCon.setRequestProperty("Acccept", "application/json");
givenCon.setRequestMethod("POST");   
givenCon.connect();
OutputStreamWriter requestSender = new OutputStreamWriter(givenCon.getOutputStream());       
String JSONString = BitstampLoginJSON().toString();        
requestSender.write(JSONString);    
requestSender.flush(); 
requestSender.close();
} 
catch(IOException e) {
e.printStackTrace();
}
}

I get a response code 200 and returned message of "OK". Bitstamp returns a JSON Object that says this:

"error": "Missing user and/or password POST parameters"}

I'm quite confused as to why Bitstamp is not receiving or accepting my JSONObject. I have read about a half dozen posts on SO about JSON and POSTing but I can't seem to get it.

Bad Wolf
  • 8,206
  • 4
  • 34
  • 44

0 Answers0