[HTTP] Force multipart/form-data without having to call addPostFiles().
| From: | Jason Cipriani | Date: | Thu, 05 Mar 2009 00:53:21 +0000 |
| Subject: | [HTTP] Force multipart/form-data without having to call addPostFiles(). | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-6193@lists.php.net to get a copy of this message | ||
I have two questions:
I am trying to make an HTTP request to a server that expects multipart
data, but this particular request does not have a file attached. I
noticed that when I set the method to post and call just
addPostFields, it encodes as application/x-www-form-urlencoded, but
when I call addPostFiles to add a file, it encodes as
multipart/form-data.
Is there a way to force it to use multipart/form-data even without
calling addPostFiles?
I'm looking at the source code (http_request_body_fill in
http_request_body_api.c, version 1.7.0b1), and I can see logic like
this:
if (files present) {
multipart encode fields and files
} else if (fields present) {
url encode fields
} else {
...
}
So it appears that there is no way to force multipart data... is this
true? If so, it's incredibly frustrating, because the feature I need
is right at my finger tips but I can't get to it through PHP. I can
see the logic in the source that would need to be changed to make that
happen, but a custom PECL build is not an option, unfortunately.
What's the best way to send multipart data without a file attached?
My second question is:
Is there a way to send multipart/form-data encoded post requests when
the data for the file is in memory (e.g. posted to a PHP script and
you are echoing it to another server) rather than in a server-side
file?
Thanks!
Jason