Can't send POST variables through telnet? - php

I know it is very simple, but I can't figure it out, if I make a request with telnet like this:
machine:~ user$ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.
POST / HTTP/1.1
Host: localhost
Content-Length: 7
vari=e3
HTTP/1.1 200 OK
Date: Thu, 10 Jul 2014 18:06:33 GMT
Server: Apache/2.2.26 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.6 PHP/5.5.10 mod_ssl/2.2.26 OpenSSL/0.9.8y DAV/2 mod_perl/2.0.8 Perl/v5.18.2
X-Powered-By: PHP/5.5.10
Content-Length: 7
Content-Type: text/html
VARI =
The vari variable isn't set... the response should have VARI = e3 cause I have a PHP line that outputs it:
echo "VARI = ".$_POST['vari'];
exit;
But the variable doesn't appear. Am I missing something?

Try adding the Content-type header:
Content-type: application/x-www-form-urlencoded

Related

HAProxy health check not working but CURL returns 200 OK

I have a HAProxy health check configured with the following backend:
backend php_servers
http-request set-header X-Forwarded-Port %[dst_port]
option httpchk get /health
http-check expect status 200
server php1 internal_ip:80 check
HAProxy doesn't enable the server but when using CURL I receive a 200 OK response.
Command: curl -I internal_ip/health
Response:
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 01 Dec 2016 20:53:48 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Access-Control-Allow-Origin: api.flex-appeal.nl
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-transform
Why doesn't HAProxy recognize the servers as "UP"? Seems I can connect just fine.
The correct HTTP verb is GET, not get:
option httpchk GET /health
You can also check/enable the stats page: on the LastChk column you will see why the check fails. In my case, I get a 501 Not Implemented response.
I can reproduce it by doing the same request as HAProxy:
$ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.
get /health HTTP/1.0
HTTP/1.1 501 Not Implemented
Date: Thu, 01 Dec 2016 21:53:09 GMT
Server: Apache/2.4.23 (Unix) PHP/7.0.13
[...]

How can I prevent nginx from buffering within PHP?

I am trying to push a page to the browser while it is being generated from a PHP script. I have no access to my hosting provider's nginx configuration but they have told me that they use nginx 1.8.1. In my phpinfo() output I can see
output_buffering 0 0
and the same script works as expected on my local PC.
This is my starting script:
<pre>
<?php
for ($i = 0; $i < 100; ++$i) {
print('<b>.</b>');
flush();
usleep(100000); // 0.1 second
}
?>
</pre>
I start getting output immediately on my local PC but I have to wait the full 10 seconds before I see anything when the page is accessed from my hosting.
These are the default response headers:
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 12 Apr 2016 12:32:05 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.4.45
Content-Encoding: gzip
If I add
<?php
header('X-Accel-Buffering: no');
I get
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 12 Apr 2016 12:35:10 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.4.45
Content-Encoding: gzip
<?php
header('X-Accel-Buffering: no');
header('Content-Encoding: identity');
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 12 Apr 2016 12:37:11 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 812
Connection: keep-alive
X-Powered-By: PHP/5.4.45
Content-Encoding: identity
Obviously, if the server knows the length of the content, it has waited for the script to finish before starting to send it to the browser.
These are the headers on my local machine:
HTTP/1.1 200 OK
Date: Tue, 12 Apr 2016 12:52:31 GMT
Server: Apache/2.4.7 (Win32) PHP/5.4.45 OpenSSL/1.0.1e
X-Powered-By: PHP/5.4.45
X-Accel-Buffering: no
Content-Encoding: identity
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
The X-Accel-Buffering header gets passed through because I am not running nginx locally.
Are there any other headers I can pass through from PHP to stop nginx from buffering the content? So far I've only found config options, which I don't have access to.

Chrome totally ignoring Access-Control-Allow-Origin: * header

I am setting this with htaccess. I know it's being set properly because if I set another header:
Header set Access-Control-Allow-Origin2: *
Then chrome does see this. As soon as I remove the 2 however, chrome just completely ignores it. If I make my file a PHP file and put this in it:
<?php header("Access-Control-Allow-Origin: *"); ?>
Then it works.
Here are the response headers as reported by Chrome of the .htaccess method which I need to work and which does not:
HTTP/1.1 304 Not Modified
Date: Sun, 30 Mar 2014 00:13:06 GMT
Server: Apache/2.2.22 (Ubuntu)
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
ETag: "208f3-178a2-4f5c4f119cd34"
Vary: Accept-Encoding
Here are the response headers as reported by Chrome from the PHP method which for some reason does work:
HTTP/1.1 200 OK
Date: Sun, 30 Mar 2014 00:13:09 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.10
Access-Control-Allow-Origin: *
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 23
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html
Again, I know the htaccess is setting the header, even if I go to an online service that checks reponse headers, I see this back:
HTTP/1.1 200 OK
Date: Sun, 30 Mar 2014 00:18:14 GMT
Server: Apache/2.2.22 (Ubuntu)
Last-Modified: Sat, 29 Mar 2014 20:48:34 GMT
ETag: "208f3-178a2-4f5c4f119cd34"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Access-Control-Allow-Origin: *
Content-Length: 33393
Content-Type: application/javascript

curl doesn't get 302 but 200

I am using curl to retrieve content from a website, but the http code retrieved by curl is 200 and the content is empty. When I used this on firefox, I see a 302 redirection. I have already addes this line:
curl_setopt($http, CURLOPT_FOLLOWLOCATION, true);
When I used the command line, I get the same result:
curl -I -L http://www.caudalie.fr
In Firefox, the final location will be http://fr.caudalie.com/ but curl never gets this.
Have you an idea?
I tried some different request headers, starting from the headers Firefox sent. The minimum doesnt work:
bf#desktop-bf:~$ telnet www.caudalie.fr 80
Trying 178.16.174.50...
Connected to www.caudalie.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.caudalie.fr
Connection: keep-alive
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 26 Apr 2013 07:23:36 GMT
Content-Type: text/html
Connection: keep-alive
Expires: Sat, 26 Jul 1997 05:00:00 GMT
Vary: Accept-Encoding
Content-Length: 0
I got a redirect if I give a language:
bf#desktop-bf:~$ telnet www.caudalie.fr 80
Trying 178.16.174.50...
Connected to www.caudalie.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.caudalie.fr
Accept-Language: nl,en;q=0.7,en-us;q=0.3
HTTP/1.1 302 Found
Server: nginx
Date: Fri, 26 Apr 2013 07:23:55 GMT
Content-Type: text/html
Connection: keep-alive
Expires: Sat, 26 Jul 1997 05:00:00 GMT
Location: http://fr.caudalie.com/
Vary: Accept-Encoding
Content-Length: 0
So, add a Accept-Language header and you should be OK. In PHP, that would be:
curl_setopt($http,CURLOPT_HTTPHEADER,array('Accept-Language: nl,en;q=0.7;en-us;q=0.3'));
See also here: How to send a header using a HTTP request through a curl call?

Zend_Amf headers

I'm using charles proxy to debug a zend amf response. The headers are coming back as:
HTTP/1.1 200 OK
Date: Sat, 29 Aug 2009 10:04:32 GMT
Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8k DAV/2 PHP/5.3.0
X-Powered-By: PHP/5.3.0
Content-Length: 33
Content-Type: text/html; charset=utf-8
Should the content type be application/x-amf.
Does apache need something special to do this?
Thanks
The headers should be x-amf. Something in my php script was corrupting the output. The charles proxy item should have an 'A' icon. I didn't have to add anything in Apache.

Categories