I have an website. Let's call it http://www.domain.com
. Now, on this domain.com I want to display the file contents of http://www.adserversite.com/ads.php
. How can I do that with cURL or another method? I don't want to use iframe
.
Thanks
I have an website. Let's call it http://www.domain.com
. Now, on this domain.com I want to display the file contents of http://www.adserversite.com/ads.php
. How can I do that with cURL or another method? I don't want to use iframe
.
Thanks
I was finally able to do this via CURL and an access token. First, I would say that the OAuth Playground is very useful. There are 2 main components needed to do this: first, you need your XML formatted correctly. Secondly, you need your access token put into the header of the CURL instance. Below is the code I used, and it works just fine:
session_start();
$temp = json_decode($_SESSION['token'], true);
$access = $temp['access_token'];
$contactXML = '<?xml version="1.0" encoding="utf-8"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
<atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
<gd:name>
<gd:givenName>Jackie</gd:givenName>
<gd:fullName>Jackie Frost</gd:fullName>
<gd:familyName>Frost</gd:familyName>
</gd:name>
<gd:email rel="http://schemas.google.com/g/2005#home" address="jackfrost@gmail.com"/>
<gd:phoneNumber rel="http://schemas.google.com/g/2005#home" primary="true">1111111111</gd:phoneNumber>
</atom:entry>';
$headers = array(
'Host: www.google.com',
'Gdata-version: 3.0',
'Content-length: '.strlen($contactXML),
'Content-type: application/atom+xml',
'Authorization: OAuth '.$access
);
$contactQuery = 'https://www.google.com/m8/feeds/contacts/default/full/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $contactQuery );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $contactXML);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_exec($ch);
I hope this helps anyone else who is looking for this answer. Playing around with the playground will help you find the right URLs to use and the right parameters required in the header.
cURL is not able to verify the authenticity of the certificate being used, because the certificate for the signing authority cannot be found in the local database.
This might be symptomatic of a self signed certificate being used.
What you should do is add the certificate for the signing authority to /etc/ssl/certs/ca-certificates.crt
.
What you can do is use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
, which will disable the check that is failing.
You really should use the first option.
you should check examples from here http://php.net/manual/en/curl.examples.php
Bellow is the code for you case,
$url = "http://build:f9280f75396f83a0@mobile-jenkins.domain.com:8080/job/android-test/buildWithParameters";
$data = "POST_RESULTS=true&RUN_ID=".$testrun_id."&CHECK_NAME=SampleAutomatedPlan";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
UPDATE: Using POST with file uploading :-)
$fileContents = file_get_contents("/tmp/myfile_2_3.xml");
$defaults = array(
CURLOPT_CUSTOMREQUEST => "post",
CURLOPT_HEADER => 1,
CURLOPT_URL => "http://example.com/url",
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => $fileContents,
CURLOPT_HTTPHEADER => array("a-token" => "myTokenValue", "Content-Type" => "application/xml"),
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
Who needs curl for this simple task?