Bitcoin Forum
December 06, 2016, 04:11:13 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Accessing MT Gox API from Java  (Read 1487 times)
ravenlord
Newbie
*
Offline Offline

Activity: 5


View Profile
June 13, 2011, 07:37:14 PM
 #1

Hi there,

I currently try to access the MT Gox API from a Java-Tool. No matter which code I use, it always results in a "{"error":"Not logged in."}" error. Therefore I hope, that you can help me...

I think, the following code should result in a correct POST-Request.
_url = https://mtgox.com:443/code/getFunds.php
_postcontent = name=blah&pass=blah

Code:
urlConnection = (HttpsURLConnection) (new URL(_url).openConnection());
           
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
           
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-length", String.valueOf(_postcontent.length()));
urlConnection.setRequestProperty("Content-Type", "application/x-www- form-urlencoded");

dataOutputStream = new DataOutputStream(urlConnection.getOutputStream());
LOGGER.debug("writeBytes {}", _postcontent);
dataOutputStream.writeBytes(_postcontent);
dataOutputStream.flush();
dataOutputStream.close();

I would be very happy, if somebody could help me out of this!

Thanks a lot.
1481040673
Hero Member
*
Offline Offline

Posts: 1481040673

View Profile Personal Message (Offline)

Ignore
1481040673
Reply with quote  #2

1481040673
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481040673
Hero Member
*
Offline Offline

Posts: 1481040673

View Profile Personal Message (Offline)

Ignore
1481040673
Reply with quote  #2

1481040673
Report to moderator
vrotaru
Jr. Member
*
Offline Offline

Activity: 35


View Profile
June 14, 2011, 04:25:35 AM
 #2

"POST" or "GET"? I was only reading their ticker from JAVA, and it worked with "GET"

Code:
String tickerURL = "https://mtgox.com/code/ticker.php";

URL url = new URL(tickerURL);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));
String line = bufferedReader.readLine();
bufferedReader.close();
ravenlord
Newbie
*
Offline Offline

Activity: 5


View Profile
June 14, 2011, 07:29:31 PM
 #3

MtGox requires POST requests for all API-Actions, which need a login.  Only the three open action can be performed with a get-Request.
holgero
Newbie
*
Offline Offline

Activity: 21


View Profile WWW
July 03, 2011, 01:18:13 PM
 #4

This works for me:
Code:
        final URL url = new URL("https://mtgox.com/code/getFunds.php");
        final HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
        urlConn.setDoInput(true);
        urlConn.setDoOutput(true);
        urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        urlConn.setRequestMethod("POST");
        final DataOutputStream printout = new DataOutputStream(urlConn.getOutputStream());
        final String content = "name=" + URLEncoder.encode(USERNAME, "UTF-8") + "&pass=" + URLEncoder.encode(PASSWORD, "UTF-8");
        printout.writeBytes(content);
        printout.flush();
        printout.close();

Did you forget to URLEncode your username and password? Or is the typo where you set the "Content-Type" to
Code:
"application/x-www- form-urlencoded"
really there?
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!