Created
September 27, 2013 13:58
-
-
Save roryl/6729018 to your computer and use it in GitHub Desktop.
Make a request in Java instead of CFHTTP to resolve SNI issues
This file contains 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
<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)#"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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="{}");