HTTP/1.1 400 BAD REQUEST Error - php

My coding is this
$number1= $_POST{'username'};
set_time_limit(0);
error_reporting(0);
$post = array(
'phone_number'=>$number1);
$url="https://www.pokketdeal.com/lokiapp/otp";
$headers[]='Content-Type: application/json';
$headers[]='Content-Length: 31';
// $headers[]='X-Mclient: 3';
// $headers[]='x-wap-profile: http://www.1066.cn/uaprof/prof/Micromax/Micromax_A177.xml';
// $headers[]='X-Requested-With: com.pokkt.app.pocketmoney';
$headers[]='Accept-Encoding: gzip,deflate';
$headers[]='Accept-Language: en-US';
$headers[]='Accept-Charset: utf-8, utf-16, *;q=0.7';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_USERAGENT, "okhttp/2.3.0" );
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
echo $html. "<br>";
when submitting data i am getting server response as
HTTP/1.1 400 BAD REQUEST Server: nginx/1.4.6 (Ubuntu) Date: Thu, 10 Dec 2015 12:16:40 GMT Content-Type: text/html Transfer-Encoding: chunked Connection: keep-alive X-Frame-Options: SAMEORIGIN
Bad Request (400)
also my content type is application/json but response is text/html.

Related

How to create proxy in PHP

I'm trying to create a proxy in PHP. When I visit the page http://example.com everything is OK, but using cURL, I always get a 401 Unauthorized Error.
My code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, getallheaders());
curl_setopt($ch, CURLOPT_URL, 'http://example.com');
print_r(curl_exec($ch));
The response:
HTTP/1.1 401 Unauthorized
Content-Type: text/html
Server: Microsoft-IIS/7.5
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
X-Powered-By: ASP.NET
Date: Thu, 20 Oct 2016 01:30:11 GMT
Content-Length: 1293

404 Not found error while calling clickbank webservices

error_reporting(E_ALL);
ini_set("display_errors", 1);
$ch = curl_init();
//$qry_str='?&type=RFND&comment="API refund check"&reason=ticket.type.cancel.7&refundType=FULL';
// curl_setopt($ch, CURLOPT_URL, 'https://api.clickbank.com/rest/1.3/tickets/N5GNE72J/'.$qry_str);
//https://api.clickbank.com/rest/1.3/tickets/RRBKQV4E/?type=rfnd&comment=&reason=ticket.type.refund.7&refundType=FULL
//curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.3/tickets/RRBKQV4E");
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.3/tickets/RRBKQV4E/?type=RFND&comment=&reason=ticket.type.cancel.7&refundType=FULL");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '180');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml","Authorization:DEV-B4VTK7HDKAPDR9842SODK8GI49KAHTHL:API-59RD4F7BORDB7SELOII28DV0EMLIB3IT"));
$result = curl_exec($ch);
$errorCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlInfo = curl_getinfo($ch);
$curlError = curl_error($ch);
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
When above code is run I am getting below error :
HTTP/1.1 404 Not Found
Date: Thu, 14 Aug 2014 08:14:19 GMT
Server: Apache/2.2.27 (FreeBSD) mod_jk/1.2.40 mod_ssl/2.2.27 OpenSSL/0.9.8y
Content-Length: 363
Vary: Accept-Encoding
Content-Type: text/html
Please someone help, I am struggling with this for last 1 week but no success.
After a long struggle found the solution. Use below code it worked for me.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://api.clickbank.com/rest/1.3/tickets/627JE7CZ/?type=rfnd&comment=&reason=ticket.type.refund.7&refundType=FULL");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
/**
* ClickBank doesn't allow POST parameters to be sent in; however, for the CURL POST to work correctly, the
* CURL_POSTFIELDS option must be set, so we'll just set it to empty and put all our request parameters on the URL
*/
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/xml",
"Authorization:DEV-enter your dev key here:API-enter your clerk key here"
));
$result = curl_exec($ch);
curl_close($ch);
?>

Clickbank API in php?

i need to get digital products from click bank, so am using their API to get products, unfortunately given example code given by them are not working, am using CURL to do this ,
code is below :
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.clickbank.com/rest/1.3/products/list");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization:DEV-KEY:API-KEY"));
$result = curl_exec($ch);
curl_close($ch);
print $result;
?>
but i got the below error
HTTP/1.1 400 Bad Request Date: Thu, 21 Feb 2013 05:20:47 GMT Server: Apache/2.2.23 (FreeBSD) mod_jk/1.2.37 mod_ssl/2.2.23 OpenSSL/0.9.8x Vary: Accept-Encoding Connection: close Transfer-Encoding: chunked Content-Type: text/plain The API call (/api/rest/1.3/products/list) requires parameters which are missing : [site]1
have any one got this error before ?
It's expecting a parameter called site. Please see the docs here:
https://api.clickbank.com/rest/1.3/products
Try This:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.clickbank.com/rest/1.3/products/list?site=<your unique affiliate id>");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization:DEV-KEY:API-KEY"));
$result = curl_exec($ch);
curl_close($ch);
print $result;
?>

How to list out product details from click bank API and XML?

This is my sample code for click bank API unfortunately this script do not work
Here is the sample code:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.3/products/list");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization: DEV:CLERK"));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
?>
If run this code following error has occur
HTTP/1.1 400 Bad Request Date: Sat, 23 Feb 2013 05:24:10 GMT Server: Apache/2.2.23 (FreeBSD) mod_jk/1.2.37 mod_ssl/2.2.23 OpenSSL/0.9.8x Vary: Accept-Encoding Connection: close Transfer-Encoding: chunked Content-Type: text/plain The API call (/api/rest/1.3/products/list) requires parameters which are missing : [site]1
https://api.clickbank.com/rest/1.3/products
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.2/debug");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization: DEV:CLERK"));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
?>
The required "site" parameter should be the Clickbank ID (also known as vendor).

Rest-ClickBank sandbox post api not working

I am trying to use Sandbox Api of clickBank which accepts a post request.
But somehow it doesnot work.
I am calling clickBank's Prepare Api (https://sandbox.clickbank.com/rest/1.2/sandbox/prepare) using a POST method.
But it giving me this error
HTTP/1.1 405 Method Not Allowed Date: Wed, 07 Nov 2012 12:08:32 GMT Server: Apache/2.2.22 (FreeBSD) mod_jk/1.2.32 mod_ssl/2.2.22 OpenSSL/0.9.8q Allow: POST,OPTIONS Content-Length: 1034 Content-Type: text/html;charset=utf-8 1
Here is my code.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://sandbox.clickbank.com/rest/1.2/sandbox/prepare");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
//curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization:". $dev_key .":" .$api_key ));
$result = curl_exec($ch);
curl_close($ch);
print $result;
I tried everything but it doesnot seem to work.
Any help would be highly appreciated.
Thanks in Advance.
Try this :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://sandbox.clickbank.com/rest/1.3/sandbox/prepare");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept:application/json", "Authorization: >>>Your Clickbank Developer API Key from ClickBan->Settings->My Account<<<"));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
$return = curl_exec($ch);
curl_close($ch);
Try adding this before your curl_exec():
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
It worked for me, I hope it will work for you too.

Categories