Last active
December 17, 2015 10:58
-
-
Save AntonNguyen/5598445 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.logging.LogFactory; | |
import org.apache.http.client.methods.HttpPost; | |
import org.apache.http.entity.mime.*; | |
import org.apache.http.entity.mime.content.*; | |
import org.apache.http.impl.client.DefaultHttpClient; | |
import org.apache.http.Header; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.util.EntityUtils; | |
import org.apache.http.entity.StringEntity; | |
import javax.net.ssl.*; | |
import java.security.cert.X509Certificate; | |
import org.apache.http.conn.ssl.SSLSocketFactory; | |
import java.security.SecureRandom; | |
import org.apache.http.conn.scheme.*; | |
import org.apache.http.conn.ClientConnectionManager; | |
import org.apache.http.conn.scheme.Scheme; | |
import org.apache.http.impl.conn.SingleClientConnManager; | |
import java.nio.charset.Charset; | |
import java.io.*; | |
import org.apache.commons.codec.binary.Base64; | |
public class Arpit { | |
public static void main(String[] args) throws Exception { | |
// Build our authorization header | |
String authenticationToken = "54de7a8c750357f87c4738e717fa6580"; | |
authenticationToken = authenticationToken + ":X"; | |
authenticationToken = new String(Base64.encodeBase64(authenticationToken.getBytes())); | |
String authorization = "Basic " + authenticationToken; | |
// The API call we want to make | |
StringEntity xml = new StringEntity("<?xml version='1.0' encoding='utf-8' ?><request method=\"invoice.list\"></request>", "UTF-8"); | |
// Prepare our request | |
HttpPost request = new HttpPost( "https://notapplicable-accounts.freshbooks.com/api/2.1/xml-in" ); | |
request.addHeader( "Authorization", authorization); | |
request.addHeader( "Content-Type", "application/x-www-form-urlencoded"); | |
request.addHeader( "User-Agent", "FreshBooks-Java" ); | |
request.removeHeaders( "Content-Length" ); | |
request.setEntity( xml ); | |
// Make a request | |
DefaultHttpClient client = new DefaultHttpClient(); | |
HttpResponse response = client.execute(request); | |
// Examine the response | |
String inputLine ; | |
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); | |
try { | |
while ((inputLine = in.readLine()) != null) { | |
System.out.println(inputLine); | |
} | |
in.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("RESPONSE END"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment