4

The page I want to parse could be get only by POST method.

This is easy for Java as I can see:

import org.jsoup.Jsoup;
Response res = Jsoup.connect("URL").method(Method.POST).execute();
Document doc = res.parse();

I could not produce the same thing using CFscript.

jsoup = createObject("java", "org.jsoup.Jsoup");
response = jsoup.connect("URL").method(Method.POST).execute();
if (response.statusCode() == 200)
{
    doc = response.parse();
}

-ERR Element POST is undefined in METHOD

I tried almost everything. I was unable to use .method() and .execute() at the same time.

If I call .get() or .post() directly I can not check statusCode() back then.

master-lame-master
  • 3,101
  • 2
  • 30
  • 47
  • 2
    Why was this down voted? It contains a clear example, error message and describes the issue and how they tried to solve it. – Leigh Apr 11 '16 at 22:07

2 Answers2

5

If you look at the API, Method is another JSoup class. You need to create an instance of that class before you can access the POST constant. Also, Method is a little different than your typical java class. It is an enum (or constant). Those are essentially handled as inner classes, which require a special syntax with createObject:

methodClass = createObject("java", "org.jsoup.Connection$Method");
response = jsoup.connect("http://example.com").method(methodClass.POST).execute();
Community
  • 1
  • 1
Leigh
  • 28,765
  • 10
  • 55
  • 103
0

Alternatively, you can invoke the post() method directly:

response = jsoup.connect("URL").post();
Stephan
  • 41,764
  • 65
  • 238
  • 329