What is the issue?
We need to extract X-CardConnect-SessionKey from the response header of Card-Connect API. We are using v2/connect API of CardConnect through PHP-CURL method.
What we have done to extract the header?
We are using below methods of PHP to get the headers from the response
get_headers | getallheaders
Passing the below parameters in the CURL request:
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_HEADER => 1,
CURLINFO_HEADER_OUT => 1,
CURLOPT_NOBODY => 1,
Our Observations.
When we call the same API from PostMan we are able to see X-CardConnect-SessionKey in the response header, but when we dump full header using the above methods not getting that same key highlighted in below screen-shot.
Related
I have searched a lot, and found many related questions and forums related to this, but this one is a challenging one.
I'm trying to POST a complex array via curl. It has to be form-data while the first value in the array is of type JSON.
The two other values of array are two images which are uploaded and ready to send.
I tried to run it in Postman, and works perfectly fine. I used the generated PHP code from Postman, but it is not working. Seems like postman is handling some of its tricks without revealing them to us.
Any way, I'm posting a Postman image to illustrate what I mean:
As you can see, I'm sending the data in form-data tab, my first value (param1) is a JSON with content-type application/json, the second and third values are images uploaded in Postman.
This works just fine in Postman.
The problem is, if I set Content-Type:multipart/form-data in header, the destination server throws an error saying the content-type must be JSON.
If I set the Content-Type:application/json in header, the destination server says content must be of type Multipart.
Somehow, I need to set both content-types. The main one as form-data and the one for param1 as JSON.
I paste the Postman code as well, may that be a good start for you fellas to help out with the code.
Postman Code:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://xxxxx.com/xxxx/xxx/xxxx',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('param1' => '{
"AgentId":"1414",
"ContractId":36529,
"Files":[
{
"FileName":"car_card_front_image.png",
"FileTypeId":2
},
{
"FileName":"car_card_back_image.png",
"FileTypeId":2
}
]
}','param2'=> new CURLFILE('/C:/images/icons/car_card_back_image.png'),'param3'=> new CURLFILE('/C:/images/icons/car_card_front_image.png')),
CURLOPT_HTTPHEADER => array(
'authenticationToken: xxxx-xxx-xx-xxxxxxxx'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
The PHP generated code by postman, is not working. One of the reasons can be that there's no content-type mentioned in it.
I tried modifying the code, adding content-types in header and in parameter, nothing seems to work.
If Postman can do it, we should be able it too, right?
Go ahead, make as much changes as you would or suggest anything that comes to your mind, I will test them all.
Cheeeeers...
May i suggest the ixudrra/curl library ?
It would make your life easier ....
$response = Curl::to('http://example.org')
->withData( array( 'Foo' => 'Bar' ) )
->withFile( 'image_1', '/path/to/dir/image1.png', 'image/png', 'imageName1.png' )
->withFile( 'image_2', '/path/to/dir/image2.png', 'image/png', 'imageName2.png' )
->post();
I have integrate payfast payment gateway in our Laravel 5.1 website, it is working perfect on our development server but when we move site on live server it give error in ITN request step, here is the error which I am getting:
HTTP/1.1 500 Internal Server Error
Date: Wed, 09 Nov 2016 14:10:09 GMT
Server: Apache
Cache-Control: no-cache, private
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
When I am searching for solution I got below option to enable ITN request without CSRF token
protected $except = [
//
'/itn'
];
but this also not working, I put sample code folder on my website root folder and try to do payment and that will working.
Also when I try to write notify response in text file it print success in response to the file.
After debugging my code I found there is problem with the CURL post.
// Base settings
$curlOpts = array(
// Base options
CURLOPT_USERAGENT => USER_AGENT, // Set user agent
CURLOPT_RETURNTRANSFER => true, // Return output as string rather than outputting it
CURLOPT_HEADER => false, // Don't include header in output
CURLOPT_SSL_VERIFYHOST => true,
CURLOPT_SSL_VERIFYPEER => false,
// Standard settings
CURLOPT_URL => 'https://' . $pfHost . '/eng/query/validate',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $pfParamString,
);
curl_setopt_array($ch, $curlOpts);
// Execute CURL
$res = curl_exec($ch);
curl_close($ch);
Main issue occurs because of these two line code
CURLOPT_SSL_VERIFYHOST => true,
CURLOPT_SSL_VERIFYPEER => false,
I change its value and it start working
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => true,
This will fix my problem and payfast working perfect after doing these changes.
I'm trying to scrape the below feed (with permission) via PHP cURL:
http://www.safc.com/Home/RSS Feeds/News%20Feed
Loads fine in a browser, but gives me a 400 'bad request' with cURL.
$ch = curl_init($uri); //http://www.safc.com/Home/RSS Feeds/News%20Feed
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => CURL_CONNECT_TIMEOUT,
CURLOPT_USERAGENT => CURL_USER_AGENT,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => true
));
$ret = curl_exec($ch);
Result is a 400; I know this from looking in curl_getinfo().
CURL_USER_AGENT is an arbitrary identifier as I realised some other feeds wouldn't spit out content unless this header was present. I have tried removing the headers one by one, and tried adding a few more, but that approach feels a bit needle/haystack.
Before I approach the owners of the site, does anyone know how I might resolve this?
use http://www.safc.com/home/rss%20feeds/news%20feed check different between "Home" and "home" there is 301 redirect when you use "Home".
I am going to send a Log in request to the server by using CURL in my PHP code. This request is POST and I wrote following code,
if (strpos($header, 'POST') !== false){
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 1,
CURLOPT_URL => $url,
CURLOPT_USERAGENT => 'proxy',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $postParameters,
CURLOPT_COOKIE => $postCoockies
));
$respond = curl_exec($curl);
curl_close($curl); }
and if I want to say what my variables are here:
$url is the exact String after POST and before HTTP/1.1.
when I want to send the GET request also, I am using this part as my urs which would be contained all parameters in my query String.
$postParameters is the exact String that exist in POST body.
(That's a String, not an associative array)
$postCoockies in the exact String after Cookie: in my request header.
(again, that's not an associative array)
My problem is:
When I send this request, server sends me back a response to only the URL I am passing. Which is to load the login page again! it seems that the server is not receiving my parameters!
Also, when I used GET request for login (I have access to the source code of website), and sent the whole URL and parameters inside the $url, the same thing happened.
Am I wrong somewhere in sending my request?
Should I consider something else here?
I have an issue with SounCloud PHP wrapper. When I make an oembed request to the SounCloud API. This last one gives me back a string data. It's composed by something like a header and the JSON data. It looks like this:
Age: 0
Via: 1.1 varnish
X-Cache: MISS
Vary: Accept-Encoding
{"version":1.0,"type":"rich",......."author_url":"https://soundcloud.com/forss"}
So when I use json_decode function on this data it can't decode the JSON part.
Does anyone have any idea in how do delete header from this content?
NB: I am working behind an proxy so I have add this code below to make the curl request work
$client->setCurlOptions(array(
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_PROXY => "http://xxxxxxxxxx",
CURLOPT_PROXYPORT => 8080,
CURLOPT_PROXYUSERPWD => "xxxx:xxxx",
CURLOPT_SSL_VERIFYPEER => 0));
That's strange! what you can do is:
if(strstr($response, "{") !== false){
$response = substr($response, strstr("{"));
}