Java Reference
In-Depth Information
query += "&" + q("accountType", "GOOGLE");
query += "&" + q("service", "finance");
query += "&" + q("source", "myco-test-1");
//Create a request
Writer out = new OutputStreamWriter(socket.getOutputStream());
out.write("POST /accounts/ClientLogin HTTP/1.0\r\n");
out.write("Content-Length: " + query.length() + "\r\n");
out.write("Content-Type: application/
x-www-form-urlencoded\r\n");
out.write("\r\n");
out.write(query);
//send request
out.flush();
//Get Response
InputStream is = socket.getInputStream();
BufferedReader br = new BufferedReader(new
InputStreamReader(is));
String line = "";
String authToken = "";
//this call returns a few items. We need to get
//the AuthToken only out of it.
while ((line = br.readLine()) != null) {
System.out.println(line);
if (line.startsWith("Auth=")){
authToken = line.substring(
line.indexOf("Auth=")+5, line.length());
}
}
if (!"".equals(authToken)){
System.out.println("Got AUTH TOKEN=" + authToken);
}
//clean up and return token for future calls
socket.close();
return authToken;
}
//Convenience to create Secure Socket connection
private SSLSocket getSecureSocket() throws Exception {
int HTTPS_PORT = 443;
Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
Search WWH ::




Custom Search