From 1d24e1f0c1578a43e9e91c03fa379736323351b8 Mon Sep 17 00:00:00 2001 From: Dobromi Date: Sun, 16 Oct 2016 13:54:47 +0300 Subject: [PATCH 1/3] Java file making http request to API --- HttpReq.java | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 HttpReq.java diff --git a/HttpReq.java b/HttpReq.java new file mode 100644 index 0000000..feca940 --- /dev/null +++ b/HttpReq.java @@ -0,0 +1,65 @@ +package project; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; + +public class HttpReq { + + private static final String URLstr="http://www.imdb.com/xml/find?json=1&nr=1&tt=on&q="; + + private static void sendReq(String title) throws IOException{ + URL obj=new URL(URLstr+title); + HttpURLConnection con=(HttpURLConnection)obj.openConnection(); + con.setRequestMethod("GET"); + int responseCode = con.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { // success + BufferedReader in = new BufferedReader(new InputStreamReader( + con.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + String str = null; + boolean record=false; + for(int i=0;i Date: Sun, 16 Oct 2016 14:40:58 +0300 Subject: [PATCH 2/3] Some changes --- HttpReq.java | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/HttpReq.java b/HttpReq.java index feca940..c2e1ad3 100644 --- a/HttpReq.java +++ b/HttpReq.java @@ -1,5 +1,3 @@ -package project; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -42,13 +40,26 @@ private static void sendReq(String title) throws IOException{ } } - // print result + String word1="\"title\":"; + String word2="\"title_description\":"; + StringBuffer titleS=new StringBuffer(); + StringBuffer yearS=new StringBuffer(); + int index=str.indexOf(word1); + int index2=str.indexOf(word2); + for(int i=index2+word2.length();i Date: Sun, 16 Oct 2016 14:42:28 +0300 Subject: [PATCH 3/3] Some changes --- HttpReq.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HttpReq.java b/HttpReq.java index c2e1ad3..7120daf 100644 --- a/HttpReq.java +++ b/HttpReq.java @@ -67,7 +67,7 @@ private static void sendReq(String title) throws IOException{ public static void main(String[] args) { try { - sendReq("dude"); + sendReq(args[0]); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();