Rectangle 27 4

The problem is that the redirect is specified through methods that cURL won't follow.

HTTP/1.1 200 OK
Cache-Control: public, max-age=604800
Expires: Mon, 22 Jun 2009 14:58:18 GMT
Date: Mon, 15 Jun 2009 14:58:18 GMT
Refresh: 0;URL=http://mail.google.com/mail/
Content-Type: text/html; charset=ISO-8859-1
X-Content-Type-Options: nosniff
Transfer-Encoding: chunked
Server: GFE/1.3

<html>
 <head>
  <meta http-equiv="Refresh" content="0;URL=http://mail.google.com/mail/" />
 </head>
 <body>
  <script type="text/javascript" language="javascript">
  <!--
   location.replace("http://mail.google.com/mail/")
  -->
  </script>
 </body>
</html>

As you can see, the page uses both a Refresh header (and HTML meta equivalent) and javascript in the body to change location to http://mail.google.com/mail/.

If you then request http://mail.google.com/mail/, you will be redirected (with the Location header, which cURL follows) to the page you had previously mentioned W3C correctly identifies.

HTTP/1.1 302 Moved Temporarily
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Mon, 15 Jun 2009 15:07:56 GMT
Location: https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=zpwhtygjntrz&scc=1&ltmpl=default&ltmplcache=2
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Transfer-Encoding: chunked
Server: GFE/1.3

HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Cache-control: no-cache, no-store
Pragma: no-cache
Expires: Mon, 01-Jan-1990 00:00:00 GMT
Set-Cookie: GALX=B8zH60M78Ys;Path=/accounts;Secure
Date: Mon, 15 Jun 2009 15:07:56 GMT
X-Content-Type-Options: nosniff
Content-Length: 19939
Server: GFE/2.0

(HTML page content here, removed)

Perhaps you should add an additional step in your script to check for a Refresh header.

Another possible error is that you have open_basedir set in your PHP configuration, which would disable CURLOPT_FOLLOWLOCATION - you can check this quickly by turning on error reporting, as a message is generated as either a warning or notice.

The results above were all obtained with the following cURL setup:

$useragent="Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$res = curl_exec($ch);

curl_close($ch);

php - Confusion with mail.google.com, cURL and http://validator.w3.org...

php http curl
Rectangle 27 0

Along with your curl request, also send the HTTP header. For example:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));

And the post data should be:

$post_data = '{auth: {passwordCredentials : {username : myusername, password : mypassword }}}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

Good call about the header; not sure you can get away with JSON without the double quotes (see how json_encode did things in my answer)

using json_encode is the best practice. but for this case it will get away :-)

json - PHP Curl equivalent of command line curl - Stack Overflow

php json curl
Rectangle 27 0

HttpURLConnection con = (HttpURLConnection) new URL("https://www.example.com").openConnection();
con.setRequestMethod("POST");
con.getOutputStream().write("LOGIN".getBytes("UTF-8"));
con.getInputStream();

php - cURL equivalent in JAVA - Stack Overflow

java php authentication curl
Rectangle 27 0

No HTTP Client in this library, which is a shame because otherwise Apache Commons is very good (speaking from experience): commons.apache.org/net

php - cURL equivalent in JAVA - Stack Overflow

java php authentication curl
Rectangle 27 0

No HTTP Client in this library, which is a shame because otherwise Apache Commons is very good (speaking from experience): commons.apache.org/net

php - cURL equivalent in JAVA - Stack Overflow

java php authentication curl
Rectangle 27 0

If you use curl directly with the -I flag, it will return the HTTP headers (404 etc) instead of the page HTML. In PHP, the equivalent is the curl_setopt($ch, CURLOPT_NOBODY, 1); option.

php - curl and ping - how to check whether a website is either up or d...

php curl webserver http-status-codes ping
Rectangle 27 0

<% 
set XmlObj = Server.CreateObject("Microsoft.XMLHTTP") 
XmlObj.open "POST", "domain.co.za?var1="; & request.form("var1") & "&firstname=" & request.form("firstname") & "&action=" & request.form("action") , false 
XmlObj.send formatdata = XmlObj.responseText 
Response.write(formatdata) 
Set XmlObj = nothing 
%>

php - Asp Classic cURL equivalent - Stack Overflow

php curl asp-classic
Rectangle 27 0

If you want to make a POST request to a php file by using an asp server-side script then you will want to check cURL (or whatever the asp equivalent is).

wow, how did you know what user1512328 meant? :O cool! :)

@Chris - lol - I was just trying to guess. If one of my kids had asked me I'd have told him to phrase the question properly, but seeing as it's a public place, I try to be nice :)

asp.net - Passing values from aspx to php via an HTML-form and then st...

php asp.net mysql
Rectangle 27 0

You should use urlopen to issue requests.

import urllib2
result = urllib2.urlopen("http://www.google.com/")
print result.read()

Python equivalent of PHP curl request - Stack Overflow

php python curl
Rectangle 27 0

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE) is the equivalent of -k on the command line (which you shouldn't really use, since it makes the connection vulnerable to MITM attacks).

Your problem here is that you're assuming that -d "pameters=here" is equivalent to putting these parameters in the URL query like this https://apiurlhere.com?parameters=here.

-d

(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded.

You should probably use POSTFIELDS for this:

curl_setopt($ch, CURLOPT_POSTFIELDS, array("parameters" => "here"));

php - What is the curl_setopt equivalent of exec('curl -k ...') - Stac...

php curl
Rectangle 27 0

Not a pure 100% Java solution but an option nonetheless. It requires the C libcurl library.

php - cURL equivalent in JAVA - Stack Overflow

java php authentication curl
Rectangle 27 0

Not a pure 100% Java solution but an option nonetheless. It requires the C libcurl library.

php - cURL equivalent in JAVA - Stack Overflow

java php authentication curl
Rectangle 27 0

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE) is the equivalent of -k on the command line (which you shouldn't really use, since it makes the connection vulnerable to MITM attacks).

Your problem here is that you're assuming that -d "pameters=here" is equivalent to putting these parameters in the URL query like this https://apiurlhere.com?parameters=here.

-d

(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded.

You should probably use POSTFIELDS for this:

curl_setopt($ch, CURLOPT_POSTFIELDS, array("parameters" => "here"));

php - What is the curl_setopt equivalent of exec('curl -k ...') - Stac...

php curl
Rectangle 27 0

is there a way to use curl such that you can do something that is equivalent to the get_meta_tags() function in php

The best way would be to fetch the data, and parse it using a HTML parser. Alternatively, there are several regex based approaches in the user contributed notes in the manual.

OP wasn't asking how to parse HTML. The answer below uses Curl to get meta tags info. Its result is equivalent to the get_meta_tags() function in php, as asked by the OP. Works like a dandy.

@Dude no, it uses curl to fetch the data, then goes on using a HTML parser to parse the info, as I also suggested. I agree that it's the better answer (and it probably should be the accepted one), but it doesn't make my answer wrong.

php - getting meta tags info using curl and get_meta_tags() - Stack...

php html curl meta-tags
Rectangle 27 0

i've used the same method lot of times, heres a little snippet from one of my active php projects.

$file = "http://the_address_of_the_xml_file.com";
if(!$xml = simplexml_load_file($file)) {
return 0;
} else {     //open
$status = $xml->attributes()->statu
if($status=='ok') {//open
$bio = $xml->artist->bio;


//closed
for ($i = 0; $i < 1; $i++) {

and how about file_get_content ?

$post_data = array('xml' => $xml_str);
$stream_options = array(
    'http' => array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded' . "\r\n",
        'content' =>  http_build_query($post_data)));

$context  = stream_context_create($stream_options);
$response = file_get_contents($url, null, $context);

ha im not on top form today, in bed really unwell ;)

->statu

You missed the part about posting data.

thanks for you response. but Sorry Guernica. i dont want to read an xml file. instead i want to send an xml data (contains request type) to the given API URL and get the response from them. then i can parse it easily.

need equivalent PHP (HttpWebRequest and Stream or curl) code for this ...

php
Rectangle 27 0

It's simple, just do as the manual says:

<?php
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,"https://view-api.box.com/1/sessions");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1); // for -i option

    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
    array('document_id' => '626ef23c0c924328b6f61505786df619', 'duration' => 60)));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Authorization: Token jizb4owywrjwi0qbcjh3l5q40rmdxt63'
    ) ); // encode data into JSON format.

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the transfer as a string

    $server_output = curl_exec ($ch);
    print "curl response is:" . $server_output;
    curl_close ($ch);
 ?>

PHP equivalent of CURL having -i in command line - Stack Overflow

php curl
Rectangle 27 0

I wouldn't bother trying to convert PHP code into python, but instead just search for a Python way of getting this answer. A little googling and it looks like this might be a duplicate:

Python equivalent of PHP curl request - Stack Overflow

php python curl
Rectangle 27 0

I have a solution to this with the help of Python.

In the .php file, just echo the output of python:

<?php
echo passthru("python python.py");
?>
import httplib
conn = httplib.HTTPSConnection('127.0.0.1');
url = "example.com"
conn.request("GET", url)
content = conn.getresponse()
print content.read()
conn.close()

http - curl --resolve equivalent in PHP CURL library - Stack Overflow

php http ssl curl
Rectangle 27 0

if you are going to bother to fork another process, just fork curl itself with the "--resolve" option versus yet another script.

http - curl --resolve equivalent in PHP CURL library - Stack Overflow

php http ssl curl
Rectangle 27 0

I wouldn't bother trying to convert PHP code into python, but instead just search for a Python way of getting this answer. A little googling and it looks like this might be a duplicate:

Python equivalent of PHP curl request - Stack Overflow

php python curl