2

I am able to reach this link manually and search properly using firefox browser but I am failing to connect using JSOUP.

Code :

String url = "https://www.sosnc.gov/trademrk/search.aspx";
Connection.Response response = Jsoup.connect(url).timeout(45000)
            .method(Connection.Method.GET)
            .ignoreContentType(true)
            .userAgent("Mozilla/5.0 (Windows NT 6.3; rv:40.0) Gecko/20100101 Firefox/40.0")  
            .followRedirects(true)
            .execute();
Map<String, String> loginCookies = response.cookies();
Document document = response.parse(); //search results
Element __VIEWSTATE = document.select("input[name=__VIEWSTATE]").first();
Element __VIEWSTATEGENERATOR = document.select("input[name=__VIEWSTATEGENERATOR]").first();
Element __PREVIOUSPAGE = document.select("input[name=__PREVIOUSPAGE]").first();
Element __EVENTVALIDATION = document.select("input[name=__EVENTVALIDATION]").first();
response = Jsoup.connect(url).timeout(45000)
            .data("SosMenu_SiteTreeView_ExpandState", "ennnnnnnnnnnn")
            .data("SosMenu_SiteTreeView_PopulateLog", "")
            .data("SosMenu_SiteTreeView_SelectedNode", "SosMenu_SiteTreeViewn2")
            .data("ToolsTreeView_ExpandState", "ennn")
            .data("ToolsTreeView_PopulateLog", "")
            .data("ToolsTreeView_SelectedNode", "")
            .data("__EVENTARGUMENT", "")
            .data("__EVENTTARGET", "")
            .data("__EVENTVALIDATION", __EVENTVALIDATION.val())
            .data("__PREVIOUSPAGE", __PREVIOUSPAGE.val())
            .data("__VIEWSTATE", __VIEWSTATE.val())
            .data("__VIEWSTATEGENERATOR", __VIEWSTATEGENERATOR.val())
            .data("ctl00$ctl00$SosContent$SosContent$Submit1", "Search")
            .data("ctl00$ctl00$SosContent$SosContent$Type", "Goods")
            .data("ctl00$ctl00$SosContent$SosContent$txtSearc", query)
            .cookies(loginCookies)
            .method(Connection.Method.POST)
            .ignoreContentType(true)
            .userAgent("Mozilla/5.0 (Windows NT 6.3; rv:40.0) Gecko/20100101 Firefox/40.0")  
            .header("host", "www.sosnc.gov")
            .referrer("https://www.sosnc.gov/trademrk/search.aspx")  
            .followRedirects(true)
            .execute();
    document = response.parse(); //search results
    System.out.println(document);

Am I missing something? It is a Jsoup post request to the server, so I have also added Cookies and the required parameters, but still failing to get results.

4
  • Have you any debug logs or exception messages ? Can you inspect the response Object ? What's inside ? Commented Sep 9, 2016 at 16:08
  • exception is the title Read timed out... and response is not coming because it is directly throwing the exception Commented Sep 9, 2016 at 16:20
  • did you try with http instead of https ? Commented Sep 9, 2016 at 16:23
  • tried but same result Commented Sep 9, 2016 at 16:43

1 Answer 1

2

I don't know why you get a timeout, but you can easily get the data in a much simpler way -

String query = "abc";
String url = "https://www.sosnc.gov/trademrk/results.aspx?searchstr=" +
              query +
             "&Type=GOODS";
Connection.Response response = Jsoup.connect(url).timeout(45000)
            .method(Connection.Method.GET)
            .ignoreContentType(true)
            .userAgent("Mozilla/5.0 (Windows NT 6.3; rv:40.0) Gecko/20100101 Firefox/40.0")

            .followRedirects(true)
            .execute();
System.out.println(response.body());

No cookies or extra parameters are needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.