Error Sending XML file by CURL to WebServices - php

I'm trying to send by POST method a XML through of CURL to authenticated webServices, but for some reason the server is rejecting the XML file, me giving me an error 500, however another WebService than by GET method, not have problem. The following code is i'm trying.
<?php
$request_xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<FiltroLicitaciones xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
<CantidadRegistro>10</CantidadRegistro>
<Texto>memo</Texto>
<CodigoRegion xsi:nil=\"true\" />
<CodigoEstado>1</CodigoEstado>
<TipoFecha>FechaPublicacion</TipoFecha>
<FechaDesde>2011-06-01T00:00:00</FechaDesde>
<FechaHasta>2011-08-01T00:00:00</FechaHasta>
</FiltroLicitaciones>";
//Initialize handle and set options
$username = 'user';
$password = 'pass';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.mercadopublico.cl/movil/licitaciones/porFecha');
//curl_setopt($ch, CURLOPT_URL, "http://localhost/server.php");
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_xml);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
?>
I don't know if will be a error for XML malformed, but server return me a random 500 error with the following header:
HTTP/1.1 500 The server encountered an error processing the request. Please see the server logs for more details.
Cache-Control: private
Content-Length: 1047
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 30 Jul 2012 23:53:05 GMT
I did a test in the local server, for see as the data came, the following the result this is:
HTTP/1.1 200 OK
Date: Mon, 30 Jul 2012 23:41:50 GMT
Server: Apache/2.2.22 (Fedora)
X-Powered-By: PHP/5.3.14
Content-Length: 2450
Connection: close
Content-Type: text/html; charset=UTF-8
Array
(
[GLOBALS] => Array
*RECURSION*
[_POST] => Array
(
[<?xml version] => "1.0" encoding="utf-8" ?>
<FiltroLicitaciones xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CantidadRegistro>10</CantidadRegistro>
<Texto>memo</Texto>
<CodigoRegion xsi:nil="true" />
<CodigoEstado>1</CodigoEstado>
<TipoFecha>FechaPublicacion</TipoFecha>
<FechaDesde>2011-06-01T00:00:00</FechaDesde>
<FechaHasta>2011-08-01T00:00:00</FechaHasta>
</FiltroLicitaciones>
)
[_GET] => Array
(
)
[_COOKIE] => Array
(
)
[_FILES] => Array
(
)
[_ENV] => Array
(
)
[_REQUEST] => Array
(
[<?xml version] => "1.0" encoding="utf-8" ?>
<FiltroLicitaciones xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CantidadRegistro>10</CantidadRegistro>
<Texto>memo</Texto>
<CodigoRegion xsi:nil="true" />
<CodigoEstado>1</CodigoEstado>
<TipoFecha>FechaPublicacion</TipoFecha>
<FechaDesde>2011-06-01T00:00:00</FechaDesde>
<FechaHasta>2011-08-01T00:00:00</FechaHasta>
</FiltroLicitaciones>
)
[_SERVER] => Array
(
[HTTP_HOST] => localhost
[HTTP_ACCEPT] => */*
[CONTENT_LENGTH] => 469
[CONTENT_TYPE] => application/x-www-form-urlencoded
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[SERVER_SIGNATURE] => <address>Apache/2.2.22 (Fedora) Server at localhost Port 80</address>
[SERVER_SOFTWARE] => Apache/2.2.22 (Fedora)
[SERVER_NAME] => localhost
[SERVER_ADDR] => ::1
[SERVER_PORT] => 80
[REMOTE_ADDR] => ::1
[DOCUMENT_ROOT] => /var/www/html
[SERVER_ADMIN] => root#localhost
[SCRIPT_FILENAME] => /var/www/html/server.php
[REMOTE_PORT] => 37712
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[REQUEST_URI] => /server.php
[SCRIPT_NAME] => /server.php
[PHP_SELF] => /server.php
[PHP_AUTH_USER] => user
[PHP_AUTH_PW] => pass
[REQUEST_TIME] => 1343691710
)
)
I hope can you help me.
Thanks.
Best Regards.

Well I'm not sure if the 500 error is from the xml but, as I see in your code the xml has no url variable :
myxml=<xml></xml>
Because as you can see from the response the url paramenter has become
[<?xml version] => "1.0" encoding="utf-8" ?>
and this is wrong.
If the api docs didn't specified any url parameters then you should probably set the right curl header :
curl_setopt($ch,CURLOPT_HTTPHEADER, Array("Content-Type: application/xml");
Like this the server knows what to expect

Note this part of your sample dump:
[_POST] => Array
(
[<?xml version]
Your XML data was interpreted as a form-type data upload, with a field name of <?xml version. This destroyed your XML's structure, leading to a parse error on the server you're submitting this to.

Read below url first i think this is very use full to you
Sending XML files to a Webservice (Using cURL)
http://softwaredevelopmentindia.wordpress.com/2007/07/09/sending-xml-files-to-a-webservice-using-curl/
or try this
Calling Web Services. Great fun!! … when it works. One of the biggest challenges is to send the XML document and get the response back, an XML document in particular. I have come up with a PHP function that hides all the necessary logic from theuser and handles the posting of the XML document and returns whatever the server responds. It relies on PHP’s cURL library (so you need it properly configured on your server in order to work). All you need to do is create the XML document, choose the URL (and port) to which you want to post the XML document and the function takes care of the rest. Below is the function code. As you can see, the function can handle SSL-enabled servers, something that provides a great advantage, since many Web services run on HTTPS.
// open a http channel, transmit data and return received buffer
function xml_post($post_xml, $url, $port)
{
$user_agent = $_SERVER[’HTTP_USER_AGENT’];
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_PORT, $port); //Set the port number
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); // add POST fields
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
if($port==443)
{
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
}
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
The example below shows how the function works, by posting a XML document of the form
<?xml version=”1.0″ encoding=”iso-8859-1″?>
<Document>
<Message>
Your Name
</Message>
</Document>
to a “listener” script, which takes the XML document and returns a reply (another XML document). In this case, the listener is very simple. All it does is replace the “Message” tag with “Reply” and print the resulting XML. Of course, the listener can do all sorts of things in response to the POST.
<?php
if ( !isset( $HTTP_RAW_POST_DATA ) )
{
$HTTP_RAW_POST_DATA = file_get_contents( ‘php://input’ );
}
$xml = str_replace(”Message”,”Reply” , $HTTP_RAW_POST_DATA);
print((trim($xml)));
?>

Related

How to simulate a real request from browser using CURL?

I'm trying to simulate a real browser request using CURL with proxy rotate, I searched about it, But none of the answers worked.
Here is the code:
$url= 'https://www.stubhub.com/';
$proxy = '1.10.185.133:30207';
$userAgent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36';
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, trim($url) );
curl_setopt($curl, CURLOPT_REFERER, trim($url));
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 0 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 0 );
curl_setopt( $curl, CURLOPT_AUTOREFERER, TRUE );
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$cacert='C:/xampp/htdocs/cacert.pem';
curl_setopt( $curl, CURLOPT_CAINFO, $cacert );
curl_setopt($curl, CURLOPT_COOKIEFILE,__DIR__."/cookies.txt");
curl_setopt ($curl, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookies.txt');
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
curl_setopt( $curl, CURLOPT_USERAGENT, $userAgent );
//Headers
$header = array();
$header[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$header[] = "Accept-Language: cs,en-US;q=0.7,en;q=0.3";
$header[] = "Accept-Encoding: utf-8";
$header[] = "Connection: keep-alive";
$header[] = "Host: www.gumtree.com";
$header[] = "Origin: https://www.stubhub.com";
$header[] = "Referer: https://www.stubhub.com";
curl_setopt( $curl, CURLOPT_HEADER, $header );
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($curl, CURLOPT_PROXY, $proxy);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$data = curl_exec( $curl );
$info = curl_getinfo( $curl );
$error = curl_error( $curl );
echo '<pre>';
print_r($all);
echo '</pre>';
Here is what I get when I run the script:
Array
(
[data] => HTTP/1.1 200 OK
HTTP/1.0 405 Method Not Allowed
Server: nginx
Content-Type: text/html; charset=UTF-8
Accept-Ranges: bytes
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: private, no-cache, no-store, must-revalidate
Surrogate-Control: no-store, bypass-cache
Content-Length: 9411
X-EdgeConnect-MidMile-RTT: 203
X-EdgeConnect-Origin-MEX-Latency: 24
Date: Sat, 03 Nov 2018 17:15:56 GMT
Connection: close
Strict-Transport-Security: max-age=31536000; includeSubDomains
[info] => Array
(
[url] => https://www.stubhub.com/
[content_type] => text/html; charset=UTF-8
[http_code] => 405
[header_size] => 487
[request_size] => 608
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 38.484
[namelookup_time] => 0
[connect_time] => 2.219
[pretransfer_time] => 17.062
[size_upload] => 0
[size_download] => 9411
[speed_download] => 244
[speed_upload] => 0
[download_content_length] => 9411
[upload_content_length] => -1
[starttransfer_time] => 23.859
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 1.10.186.132
[certinfo] => Array
(
)
[primary_port] => 42150
[local_ip] => 192.168.1.25
[local_port] => 59320
)
[error] =>
)
As well as a Recaptcha, As it says:
Due to high volume of activity from your computer, our anti-robot software has blocked your access to stubhub.com. Please solve the puzzle below and you will immediately regain access.
When I visit the website using any browser, The website is displayed.
But with the above script, It's not.
So what am I missing to make the curl request like a real browser request and not be detected as a bot?
Or if there is an API/library that could do it, Please mention it.
Would Guzzle or similar fix this issue?
"So what am I missing to make the curl request like a real browser request"
My guess is they are using a simple cookie check. There are more sophisticated methods that allow recognizing automation such as cURL with a high degree of reliability, especially if coupled with lists of proxy IP addresses or IPs of known bangers.
Your first step is to intercept the outgoing browser request using pcap or something similar, then try and replicate it using cURL.
One other simple thing to check is whether your cookie jar has been seeded with some telltale. I routinely do that too, since most scripts on the Internet are just copy-pastes and don't pay much attention to these details.
The thing that would for sure make you bounce from any of my systems is that you're sending a referer, but you don't seem to actually have connected to the first page. You're practically saying "Well met again" to a server that is seeing you for the first time. You might have saved a cookie from that first encounter, and the cookie has now been invalidated (actually been marked "evil") by some other action. At least in the beginning, always replicate the visiting sequence from a clean slate.
You might try and adapt this answer, also cURL-based. Always verify actual traffic using a MitM SSL-decoding proxy.
Now, the real answer - what do you need that information for? Can you get it somewhere else? Can you ask for it explicitly, maybe reach an agreement with the source site?

how to pass data to JSON server using cURL with POST [duplicate]

I'm trying to POST some JSON to a web service with cURL, using the following code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, 'http://index.yolink.com/index/define?o=json&ak=APIKEY');
curl_setopt($ch, CURLOPT_HTTPHEADERS,array('Content-Type: application/json'));
$data = array(
'ignore-robots' => 'false',
'language' => 'english',
'crawl-delay' => '0',
'depth' => '3',
'root' => array('url' => 'http://bartleby.com/')
);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$result=curl_exec($ch);
var_dump($result);
I get the following in return:
string(282) "HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Access-Control-Allow-Origin: * Content-Type: text/plain Content-Length: 120 Date: Fri, 18 Mar 2011 19:03:23 GMT {"code":"error.indexdefinition.invalid","message":"Invalid content provided for /define. Error:Premature end of file.."}"
I found this blog post that seems to be related -- it does seem to be sending text/plain even though I've specified the ContentType in CURLOPT_HTTPHEADERS as application/json. But adding http_build_query hasn't helped.
Thanks in advance for any help!
I believe it should be HTTPHEADER, not HTTPHEADERS.
http://php.net/manual/en/function.curl-setopt.php

$_POST is empty in php

I have gone through all the responses in this post
print_r($_POST); ===> returns empty array
print_r($_SERVER);
Array ( [HTTP_HOST] => localhost
[HTTP_ACCEPT] => */*
**[HTTP__CONTENT_TYPE]** => application/json; charset=UTF-8"
[CONTENT_LENGTH] => 942
**[CONTENT_TYPE]** => application/x-www-form-urlencoded
[PATH] => /usr/local/bin:/usr/bin:/bin
[SERVER_SIGNATURE] => Apache/2.2.14 (Ubuntu) Server at localhost Port 80
[SERVER_SOFTWARE] => Apache/2.2.14 (Ubuntu)
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /var/www
[SERVER_ADMIN] => webmaster#localhost
[SCRIPT_FILENAME] => /var/www/slocation.php
[REMOTE_PORT] => 50657
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[REQUEST_URI] => /slocation.php
[SCRIPT_NAME] => /slocation.php
[PHP_SELF] => /slocation.php
[REQUEST_TIME] => 1288466907
)
What's the difference between HTTP__CONTENT_TYPE and CONTENT_TYPE?
print_r($HTTP_RAW_POST_DATA); ==> returns correct data posted
file_get_contents('php://input'); ======> returns correct data.
Only $_POST fails.
This is my curl command
$url = "http://localhost/slocation.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('"Content-type: application/json; charset=UTF-8"'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($ch);
UPDATE::::::::::::::::::::::::::::::::::::::::::::::::::
I found a master here
To answer my own question, "What's the difference between HTTP__CONTENT_TYPE and CONTENT_TYPE?"
If you see "HTTP__CONTENT_TYPE", it most probably means you have made mistake in setting the CONTENT-TYPE header field. Probably, when curl doesn't recognize the valid CONTENT_TYPE value, then the wrong value is set to HTTP__CONTENT_TYPE and CONTENT_TYPE takes a default value.

PHP curl post to login to wordpress

I followed Wordpress autologin using CURL or fsockopen in PHP to login to wordpress, using php_curl, and it works fine as far I use WAMP, (apache/php).
But when it comes to IIS on the dedicated server, it returns nothing.
I have wrote the following function which is working fine on my local wamp, but when deployed to client's dedicated windows server 2k3, it doesn't. Please help me
function post_url($url, array $query_string)
{
//$url = http://myhost.com/wptc/sys/wp/wp-login.php
/* $query_string = array(
'log'=>'admin',
'pwd'=>'test',
'redirect_to'=>'http://google.com',
'wp-submit'=>'Log%20In',
'testcookie'=>1
);
*/
//temp_dir is defined as folder = path/to/a/folder
$cookie= temp_dir."cookie.txt";
$c = curl_init($url);
if (count($query_string))
{
curl_setopt ($c, CURLOPT_POSTFIELDS,
http_build_query( $query_string )
);
}
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie);
//curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 1);
//curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($c, CURLOPT_TIMEOUT, 60);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); //return the content
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie);
//curl_setopt($c, CURLOPT_AUTOREFERER, 1);
//curl_setopt($c, CURLOPT_REFERER, wp_admin_url);
//curl_setopt($c, CURLOPT_MAXREDIRS, 10);
curl_setopt($c, CURLOPT_HEADER, 0);
//curl_setopt($c, CURLOPT_CRLF, 1);
try {
$result = curl_exec($c);
}
catch (Exception $e)
{
$result = 'error';
}
curl_close ($c);
return $result; //it return nothing (empty)
}
Other Facts
curl_error($c); return nothing
when header CURLOPT_HEADER is set to ON,
it return this header
HTTP/1.1 200
OK Cache-Control: no-cache,
must-revalidate, max-age=0 Pragma:
no-cache Content-Type: text/html;
charset=UTF-8 Expires: Wed, 11 Jan
1984 05:00:00 GMT Last-Modified:
Thu, 06 May 2010 21:06:30 GMT
Server: Microsoft-IIS/7.0
X-Powered-By: PHP/5.2.13 Set-Cookie:
wordpress_test_cookie=WP+Cookie+check;
path=/wptc/sys/wp/ Set-Cookie:
wordpress_b13661ceb5c3eba8b42d383be885d372=admin%7C1273352790%7C7d8ddfb6b1c0875c37c1805ab98f1e7b;
path=/wptc/sys/wp/wp-content/plugins;
httponly Set-Cookie: wordpress_b13661ceb5c3eba8b42d383be885d372=admin%7C1273352790%7C7d8ddfb6b1c0875c37c1805ab98f1e7b;
path=/wptc/sys/wp/wp-admin; httponly
Set-Cookie:
wordpress_logged_in_b13661ceb5c3eba8b42d383be885d372=admin%7C1273352790%7Cb90825fb4a7d5da9b5dc4d99b4e06049;
path=/wptc/sys/wp/; httponly
Refresh:
0;url=http://myhost.com/wptc/sys/wp/wp-admin/
X-Powered-By: ASP.NET Date: Thu, 06
May 2010 21:06:30 GMT
Content-Length: 0
CURL version info:
Array ( [version_number] => 463872 [age] => 3 [features] => 2717 [ssl_version_number] => 0 [version] => 7.20.0 [host] => i386-pc-win32 [ssl_version] => OpenSSL/0.9.8k [libz_version] => 1.2.3 [protocols] => Array ( [0] => dict [1] => file [2] => ftp [3] => ftps [4] => http [5] => https [6] => imap [7] => imaps [8] => ldap [9] => pop3 [10] => pop3s [11] => rtsp [12] => smtp [13] => smtps [14] => telnet [15] => tftp ) )
PHP Version 5.2.13
Windows Server 2K3
IIS 7
Working fine on Apache, PHP 3.0 on my localhost (windows)
Quick thought: Check to make sure that temp_dir."cookie.txt" is writable by IIS.
I managed to fix it myself, it was some small fix in the wordpress rather than any IIS or PHP specific information.
I have modified wp_redirect() (just commented major part) in the following part to fix it
function wp_redirect($location, $status = 302) {
global $is_IIS;
$location = apply_filters('wp_redirect', $location, $status);
$status = apply_filters('wp_redirect_status', $status, $location);
if ( !$location ) // allows the wp_redirect filter to cancel a redirect
return false;
$location = wp_sanitize_redirect($location);
/*
if ( $is_IIS ) {
status_header($status);
header("Refresh: 0;url=$location");
} else {
if ( php_sapi_name() != 'cgi-fcgi' ) {
status_header($status); // This causes problems on IIS and some FastCGI setups
}
header("Location: $location", true, $status);
}
*/
header("Location: $location", true, $status);
}

Curl php youtube

Hi I am trying to build php youtube api without a Zend function
this is what I have till now:
function upload() {
$files = $_FILES;
$name = $files['file']['name'];
$type = $files['file']['type'];
$size = $files['file']['size'];
$tmp_nm = $files['file']['tmp_name'];
$data = array('name' => 'Foo', 'file' => '#'.$tmp_nm);
print_r($_POST);
print_r($_FILES);
echo 'Size '.$size;
$headers = array(
"Authorization: AuthSub token=".$this->auth,
"GData-Version: 2",
"X-GData-Key: key=".$this->dev_key,
"Content-length: ".$size,
"API_XML_request"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://gdata.youtube.com/action/GetUploadToken');
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_REFERER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER,0);
if($this->get_info)
{
$this->curlget_info($ch);
}
$output = curl_exec($ch);
print_r($output);
return $output;
}
The errors I get:
Output 1
Array ( [token] => TOKEN ) Array ( [file] => Array ( [name] => 0016.png [type] => image/png [tmp_name] => D:\wamp\tmp\php178D.tmp [error] => 0 [size] => 4216 ) ) Size 4216
Google
Error
Length Required
POST requests require a Content-length header.
Output 2
Array ( [token] => TOKEN ) Array ( [file] => Array ( [name] => Film.wmv [type] => video/x-ms-wmv [tmp_name] => D:\wamp\tmp\php11D3.tmp [error] => 0 [size] => 96589 ) ) Size 96589
Google
Error
Length Required
POST requests require a Content-length header.
I am using this guide.
I am trying to solve this for 5 days and I asked couple irc channels and forums. A friend linked me here to ask, I hope someone will help me :))
I don't have a developer key so I can't help you out directly, but clearly Google has a problem with your http header so you have to find out what you're sending in the header, not the message body. The best way to do this is to inspect the packet on the wire as it leaves your machine.
So install Wireshark, start it up on your WAMP server, start capturing packets, do your test, and then look at the http connection in the packet. Make sure it's what you expect.
Or maybe there's a way for curl to write the packet to a file instead of the server for debugging purposes. I don't know.
Also it's a long shot (and would rely on them being out of spec), but I noticed that you and that other person you linked to have "Content-length". Try "Content-Length" to match the example.
Not sure if this is the answer, but in the example page, they put quotes around the authsub token:
Authorization: AuthSub token="DXAA...sdb8"
Maybe try that?

Categories