Skip to content

Instantly share code, notes, and snippets.

@roryl
Created September 27, 2013 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roryl/6729018 to your computer and use it in GitHub Desktop.
Save roryl/6729018 to your computer and use it in GitHub Desktop.
Make a request in Java instead of CFHTTP to resolve SNI issues
<cfscript>
myUrl = "https://news.google.com/news?gl=us&hl=en&as_epq=chinese+medicine&as_occt=title&as_qdr=a&authuser=0&q=allintitle:++%22chinese+medicine%22&um=1&output=rss"; // web service url
objUrl = createobject("java","java.net.URL").init(myUrl);
conn = objUrl.openConnection();
//configure the request
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("GET");
//output stream actions
ostream = conn.getOutputStream();
ostream.flush();
ostream.Close();
// set input
inS =createobject("java","java.io.InputStreamReader").init(conn.getInputStream());
inVar = createObject("java","java.io.BufferedReader").init(inS);
builder = createObject("java","java.lang.StringBuilder").init(javacast("int",1000));
line = "";
do
{
line = inVar.readLine();
lineCheck = isDefined("line");
if(lineCheck)
{
builder.append(line);
}
} while(lineCheck);
retvar = builder.toString();
request.layout = false;
</cfscript>
<cfdump var="#xmlParse(retVar)#">
@jfrux
Copy link

jfrux commented Apr 10, 2015

What about other types of requests? like POST for instance? how would one add a JSON BODY in this method?

Versus the cfhttp method of conn.addParam(type='body',value="{}");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment