3
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $file);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $urls[$vidCount]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_exec($ch);
curl_close($ch);

So I have a cURL request that takes a URL and produces a file in the filesystem.

How do I emulate the above PHP cURL request in Java?

I have tried HttpURLConnection, but I am getting 403 Forbidden. The same call in cURL works properly. Is there some architecture difference between the two that I need to reconcile?

I believe it could be something in the headers that cURL might be setting automatically where Java is not. I'm not really sure but I would appreciate any advice I can get.

Thanks.

3
  • 1
    stackoverflow.com/questions/921262/… Commented Sep 26, 2012 at 14:47
  • 1
    Take a look at this question: stackoverflow.com/questions/2586975/how-to-use-curl-in-java Commented Sep 26, 2012 at 15:10
  • curl has lots of hidden features you don't see, replicating every exact query might take a few twitches and I don't think you'll find a rosetta like thing to transform, I recommend just reading the libcurl documentation in php and seeing what every option means and then see how to implement that in your java library Commented Nov 14, 2012 at 23:34

1 Answer 1

1

I am not sure why you trying to emulate PHP behavior in Java. If the end result is really what you need to reach, than use the Java HttpURLConnection or even URLConnection.

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.