Bitcoin Forum
March 28, 2024, 04:37:04 PM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Accessing MT Gox API from Java  (Read 1692 times)
ravenlord (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


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.
1711643824
Hero Member
*
Offline Offline

Posts: 1711643824

View Profile Personal Message (Offline)

Ignore
1711643824
Reply with quote  #2

1711643824
Report to moderator
"Your bitcoin is secured in a way that is physically impossible for others to access, no matter for what reason, no matter how good the excuse, no matter a majority of miners, no matter what." -- Greg Maxwell
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
vrotaru
Newbie
*
Offline Offline

Activity: 35
Merit: 0


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 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


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
Merit: 0


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:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!