3

How can I convert following code of PHP curl to JAVA HttpURLConnection?

$username = $_POST['username']; 
    $headers = array( 
    "Host: mail.google.com", 
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4", 
    "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", 
    "Accept-Language: en-us,en;q=0.5", 
    "Accept-Encoding: text", # No gzip, it only clutters your code! 
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", 
    "Date: ".date(DATE_RFC822) 
    ); 
    $c = curl_init('https://mail.google.com/mail/feed/atom'); 
    curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // use authentication 
    curl_setopt($c, CURLOPT_HTTPHEADER, $headers); // send the headers 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); // We need to fetch something from a string, so no direct output! 
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); // we get redirected, so follow 
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1); 
    curl_setopt($c, CURLOPT_UNRESTRICTED_AUTH, 1); // always stay authorised 
    $wrong = curl_exec($c); // Get it 
    curl_close($c); // Close the curl stream 
9
  • i like to know why minus?? whats the problem with this question?? Commented Dec 6, 2010 at 1:35
  • The problem is the question is not an actual, well-defined, question; you have shown no effort trying to resolve the problem yourself. It's of the "give me teh codez" variety. Commented Dec 6, 2010 at 1:41
  • who said i wasn't tried.i tried,i tried many times and failed,its above my knowledge,so i asked help...i think you dont know the answer so you are doing this Commented Dec 6, 2010 at 1:47
  • it's just one damn vote down, stop arguing, get over it and show your attempt. Commented Dec 6, 2010 at 2:01
  • 2
    seriously the down-vote sucks and I am giving it an upvote. It is a valid question which more people might like to know the answer to. That's what stackoverflow is about right? Commented Dec 6, 2010 at 2:26

1 Answer 1

1

Use Commons Http Client library,it supports HttpGet, HttpPost also , you can add Request headers, etc..

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.