When I try to upload files using HTTP post with header Content-Type: multipart/form-data; boundary=-----NPRequestBoundary----- everything works as expected but trying to use Content-Type: multipart/form-data; boundary=-----NPRequestBoundary-----; charset=UTF-8 cause completely blank $_FILES array.
Is it a problem with PHP or web server? As I know this form of Content-Type is valid.
Because the Content-Type is multipart/form-data, this means it is built up from parts, and every part can have its own Content-Type. The charset parameter is only used with text/plain content-type. So it is meanless with a multipart/form-data content-type.
Bug was fixed in SVN rev. #316373 (5.3.9 release covers it).
I've found dirty workaround for this problem. For me it's ofc temporary bcs it doesn't work under litespeed (I used reverse proxy to apache to avoid this problem).
<Location "/upload.php">
RequestHeader set Content-Type "multipart/form-data; boundary=-----NPRequestBoundary-----"
</Location>
It will force webserver to replace content-type header. For now I'm sure - this is a PHP bug (someone assumed that charset will occur before boundary=)
Related
I'm building a REST API.. Sometimes the server returns the response with chunked transfer encoding? Why is that?!
Why can't the server always return the response in the same encoding?
The problem is that I don't know how to read the data when its returned as chunked!?
update
neeed moore downvotes... to breeeath...
Assuming your server is using Apache, this is expected behaviour. You can disable it by putting this line in your .htaccess file:
SetEnv downgrade-1.0
However, you should consider modifying your reading code to just support different content encodings. What library are you using to make the HTTP request? Any reasonable HTTP library can handle chunked requests. If your requesting code is written in PHP, use curl. http://php.net/manual/en/book.curl.php
Taken from Server Fault:
specify the "Content-Length' header, so server knows, what's the size of the response
use HTTP 1.0 at the requester's side
A problem may be that Apache is gzipping your download, taking care of correcting the Content-Length, or in your case, adding the header
Content-Encoding: chunked
You can add a .htaccess RewriteRule to disable gzip:
RewriteRule . - [E=no-gzip:1]
I'm testing my API with POSTMAN and when I try to send any file the content of $request->files->all() is always empty.
$request->server->parameters["CONTENT_LENGTH"] seems to change depending on the file size. But I don't find a way to reach the file content.
Tried also with $_FILES, but the same result.
I even did a var_dump($_FILES); in my app_dev.php directly before reaching anything else from Symfony's framework.
My php.ini seems to be alright:
file_uploads: on
upload_max_filesize: more than enough
post_max_size: more than enough
In POSTMAN I tried both ways of sending a file: binary and form-data file.
A POSTMAN code example looks like this using form-data:
PUT /retain_inspecciones/web/app_dev.php/api/planningfiles/6?files=true HTTP/1.1
Host: symfony.dev
symfonytoken: Bearer my-token
Cache-Control: no-cache
Postman-Token: 9c9cd91a-99f2-57ab-a290-966074b219f3
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="fileName"; filename=""
Content-Type:
------WebKitFormBoundary7MA4YWxkTrZu0gW--
I'm not sure of why the part where the file should be is the empty string and Content-Type is empty. But it seems to be the way POSTMAN does so.
Any idea?
Finally I decided to try curl instead of Postman and it worked on first try.
I don't know how curl differs from POSTMAN when building the request but I'm happy with it.
How to remove header content-type in apache ?
The following code does not work
header_remove('content-type');
Try
<?php
header('Content-Type:');
This completely removed the Content-Type header from the response. Like you, using header_remove() didn't do a thing and Hereblur's answer left me with Content-Type: none in the response.
It depends on what php.ini directives you have, and what PHP you use (CLI, CGI, ...).
This answer is based on PHP 5.4, running in CGI.
Note in php.ini:
default_mimetype = text/html
That's the default value, that PHP sends as:
Content-Type: text/html
If you want to get rid of it, you have to remove the default value by creating the header again, then you can remove the header:
<?php
header('Content-Type: text/html');
header_remove('Content-Type');
Try this.
header("content-type: none");
I don't know why, but it's worked for me.
I cannot find any reference mentioned about this. but it's simply removed the content-type from header for me. It' may be apache's bug or PHP's bug. So try it and use it with careful.
I have a page that calls a php script. On MAMP everything works fine but when I upload it to a server I get the following error:
Call Request failed! Status code: 4000
Reason - Caught an HttpRequestValidationException due to some bad characters in the request. Make sure your post request is encoded as xml, preferable as UTF-8 ('Content-Type: text/xml; charset=utf-8'). Exception: A potentially dangerous Request.Form value was detected from the client (<?xml version="..."utf-8"?> <uclassify xmlns="ht...").
Has anyone seen anything like that?
you can check it yourself here just place a word like php or ios
It looks like your server is validating based on the content-type header. It seems to want text/xml, whereas you are sending application/x-www-form-urlencoded (which is the default for $.ajax).
Try explicitly setting the content type to text/xml in your $.ajax call. (reference)
try changing charset=utf-8 to charset=UTF-8
I'm building a REST API.. Sometimes the server returns the response with chunked transfer encoding? Why is that?!
Why can't the server always return the response in the same encoding?
The problem is that I don't know how to read the data when its returned as chunked!?
update
neeed moore downvotes... to breeeath...
Assuming your server is using Apache, this is expected behaviour. You can disable it by putting this line in your .htaccess file:
SetEnv downgrade-1.0
However, you should consider modifying your reading code to just support different content encodings. What library are you using to make the HTTP request? Any reasonable HTTP library can handle chunked requests. If your requesting code is written in PHP, use curl. http://php.net/manual/en/book.curl.php
Taken from Server Fault:
specify the "Content-Length' header, so server knows, what's the size of the response
use HTTP 1.0 at the requester's side
A problem may be that Apache is gzipping your download, taking care of correcting the Content-Length, or in your case, adding the header
Content-Encoding: chunked
You can add a .htaccess RewriteRule to disable gzip:
RewriteRule . - [E=no-gzip:1]