PHP Post - Request Entity Too Large [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
I am trying to make a POST request to a URL using Curl but getting this error?
I'm trying to make a POST request to a server using curl with some XML included, but I'm getting the error "Request Entity Too Long" Could someone point out to me what I'm doing wrong? Thanks! :)
$url = 'http://web1.trueship.com/readyreturns/company/api.php/orders?key=xxxxxxxxxxxxxxxxxx&overwrite=true';
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("&xml=".$encodedXml));
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, TRUE);
$result = curl_exec ($curl);
curl_close ($curl);
print $result;

It seems to me this message means that the request your trying to process is larger than the server is willing or able to process. You will probably need to configure your php. ini differently
The setup value you will look for is "post_max_size"
if you want to see this value but don't have access to your php set up, write a simple php page with a <? phpinfo() ?>
tag in it, it will display the php.ini values of your current configuration. you can then contact your administrator to have it modified

Related

Does Anyone Know how to Fire a Postback to Another Server using PHP? [duplicate]

This question already has answers here:
How do I send a POST request with PHP?
(18 answers)
Closed 2 months ago.
I am dealing with an affiliate marketing company and after I gather the info from a sale that was referred to my site they want me to "fire a postback" to their server in teh following format:
https://track.my affilatecompany.com/da.ashx?advertiserid=12345&clickid=&orderamount=&ordernumber="
I tried assembling the loaded URL in PHP and echoing it to the browser window with JavaScript but the affiliate company doesn't accept that. They have literally no information in their help docs, just says "fire a postback server-to-server". Any assistance would be most appreciated. Thank you.
You can use PHP Curl to make a POST request
This example will make the POST request to the affiliate.
You can use the $response variable to determine if the request was successful.
<?php
$url = "https://track.my affilatecompany.com/da.ashx?advertiserid=12345&clickid=&orderamount=&ordernumber=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$response = curl_exec($ch);
curl_close($ch);
?>

What is the use of cURL in PHP? [duplicate]

This question already has answers here:
What is cURL in PHP?
(10 answers)
Closed 5 years ago.
In PHP, I see the word cURL in many PHP projects. What is it? How does it work?
Link http://php.net/curl
Curl is a command line tool for doing all sorts of URL manipulations and transfers, but this particular document will focus on how to use it when doing HTTP requests for fun and profit. I'll assume that you know how to invoke 'curl --help' or 'curl --manual' to get basic information about it.
Curl is not written to do everything for you. It makes the requests, it gets the data, it sends data and it retrieves the information. You probably need to glue everything together using some kind of script language or repeated manual invokes.
Taken from: https://curl.haxx.se/docs/httpscripting.html
we usually use it get the Return value of a Interface like this:
$oCurl = curl_init();
if(stripos($url,"https://")!==FALSE){
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if(intval($aStatus["http_code"])==200){
return $sContent;
}else{
return false;
}

How to handle error for PHP cURL

I've done every bit of tips and answers but I can't seem to find the right solution.
my cURL is as follows
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $curlIP."api/sparts/search/");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "key=".$q."&page=".$pg);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curl);
curl_close ($curl);
What does this do?
It gets products data from a server where $q is the search key and $pg is the page number
This cURL works as intended assuming the server will always have an internet connection. As the developer we needed to have an error message whenever the cURL cannot connect to the server.
What is the problem?
For me to actually set an error message I need to know first if the error has happened. This where it gets weird for me. I tried to simulate connection failure by disabling the internet adapter of the server.
The result is:
the page stops parsing everything after the $data = curl_exec($curl);This includes the footer and everything after that line. I knew it because I tried to put echoes before and after curl_exec and it really stops there. therefore I cannot catch the error itself.
What have I tried?
I tried
PHP curl_error() - which didn't really help since the script stops at curl_exec
PHP curl_errno() - same
try and catch - This should have catch the error but it didn't which frustrates me even more.

How to call an URL with php without redirect

I'm using an URL to transmit parameters to a remote location.
I need to call the URL using PHP - without redirecting to the URL.
I've tried different solutions without luck. I am no way near an expert when dealing with PHP, I am even unsure if I am wording the question correctly.
I've tried:
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "https://remotelocation.com/storedata.aspx?name=".$name."&email=".$email_address.);
curl_exec ($curl);
curl_close ($curl);
and:
file_get_contents("https://remotelocation.com/storedata.aspx?name=".$name."&email=".$email_address.")
without any luck.
Calling the URL manually in a browser (using definite values instead of variables) the data is stored. Using mail() instead the data is also transmitted.
I know the solution must be pretty simple. Can anyone help to point me in the right direction?
Not sure why it didn't work with file_get_contents. But for curl you need to add the following few options as well(There are a lot in fact, you can check it from here).
// to handle https links
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
// return response
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
And to grab the returned response html
$response_html = curl_exec ($curl);

passing get variables without opening URL [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to read a web page in PHP
I'm sure there is some simple way to do this. I need to pass get variables through to my cart software to record a conversion, but not redirect the user, I just want the server to send GET variables to a URL. I'd rather not turn on allow_url_fopen in php.ini.
Anyone know the best way to do this? Thanks in advance.
Server side, your best option is probably to use cURL - see the documentation for details, it's not too difficult to use.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/script.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
// Failed to connect or some error occurred
} else {
// Everything was fine, check the response here if you need to
}

Categories