Re: Re: Sending multipart/form-data request with PECL.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 4, 2009 at 7:12 PM, Shawn McKenzie <nospam@xxxxxxxxxxxxx> wrote:
> Jason Cipriani wrote:
>> On Wed, Mar 4, 2009 at 2:10 PM, Shawn McKenzie <nospam@xxxxxxxxxxxxx> wrote:
>>> Jason Cipriani wrote:
>>>> Is there a way to force PECL to use multipart/form-data encoding for
>>>> all post fields added with addPostFields, even when you are not
>>>> calling addPostFile to add a file?
>>> Try: setContentType()
>>
>> Thanks! But, I tried that, and according to my packet sniffer, calling
>> setContentType() actually seems to have no effect whatsoever on the
>> request! Is there something I have to enable? Here's an example, it's
>> just a fake request, used to see what HttpRequest outputs:
>>
>> $fields = array("field"=>"value","other"=>"something")
>> $http_req = new HttpRequest('http://localhost:9999/resource');
>> $http_req->setMethod(HTTP_METH_POST);
>> $http_req->setContentType('multipart/form-data');
>> $http_req->addPostFields($fields);
>> $http_req->send();
>>
>> Here is what it produces, it's still application/x-www-form-urlencoded:
>>
>> === BEGIN REQUEST ===
>> POST /resource HTTP/1.1
>> User-Agent: PECL::HTTP/1.6.1-dev (PHP/5.2.6)
>> Host: localhost:9999
>> Accept: */*
>> Content-Length: 27
>> Content-Type: application/x-www-form-urlencoded
>>
>> field=value&other=something
>> === END REQUEST ===
>>
>> Even if I call setContentType with some made up content type, it
>> doesn't affect the output; am I doing something wrong there?
>>
>> Thanks!
>> Jason
>
> I don't know.  I just looked it up in the manual.  If it doesn't work
> then it may be a bug.  Hard to tell because the documentation for
> httprequest is very light.


Thanks. I actually had a look at the HttpRequest source code, and I
can see the logic where it switches to multipart encoding if files are
present but it actually appears that it's not possible to force it to
do that. It's sort of annoying that it's right at my finger tips but
there's no way to do it, and for sort of a silly reason (there's
arbitrarily no way to pick which encoding to use, it decides for you
even though it has the capability of doing anything). A custom PECL
build is not an option, unfortunately.

I'll have to check out the httpclient class that Manuel Lemos mentioned.

Thanks,
Jason

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux