Re: Problem using cURL with a web service
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Fri, 21 May 2010 22:38:44 -0400
JustWondering wrote:
On May 21, 6:24 pm, JustWondering <eastside...@xxxxxxxxx> wrote:On May 21, 6:10 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
JustWondering wrote:I've fired off some emails, telling them pretty much what you sayOn May 21, 4:20 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:So they're using PUT contrary to the design of the request. That's aJustWondering wrote:I am not trying to upload anything. This web service decided that theyFirst, a question: The cURL manual says that TCURLOPT_INFILE andThe PUT request is used to upload resources to the server. So you must
CURLOPT_INFILESIZE must be set to do a PUT. Some web services need a
PUT to do an update, but the operation does not involve uploading a
file. Does PUT require a file, or do I set the file location and size,
IF I have a file and I don't if I don't have a file?
Second: I did try to use PUT with a web service that requires it. The
instructions call for doing something like this:
$url=http://acme.com?key=xxx&foo[bar]=true
The service is written in Ruby. I keep getting 411 when I try to call.
I tried urlencoding everything right of the ? mark, but I'm still
getting a 411. I am doing a CURLOPT_URL, $url
The same thing happened when I did a POST (for another operation) and
did not split the URI into a url and arguments portion. So when I did:
CURLOPT_URL, $url it did not work (was getting 411)
but when I did: CURLOPT_URL, "ttp://acme.com"
CURLOPT_POSTFIELDS, "key=xxx&foo[bar]=true"
Is there to make a POST look like a PUT (so I can split the url and
postfields)?
have some resource to upload. If you don't have a file, what are you
going to upload?
Also, you should be encoding the parameter names and values - but not
the '&' separator or '=' assignment operator. And definitely NOT
"everything right of the '?' mark.
P.S. Unless you Acme Laboratories of Berkley, CA (or attempting to
access their site in your code), you should not be using their domain
name in examples. Use example.com, example.org, etc. - which are
specifically reserved for just such purpose.
want to use PUT to flag the operation as an UPDATE to an existing
record, as opposed to creation of a new record. So, I am not uploading
anything. I asked them that same question, and that's the response
they gave me.
They gave me the following command line example:
curl -X PUT --data-urlencode 'foo[bar]=true' --data-urlencode
'key=XXXX'https://example.org
They also said that if I want to use a POST, their server follows the
convention of interpreting a POST request as a PUT if it contains the
header "_method" with the value set to "put".
I googl'ed for a few hours, and came up with nothing that can help me
turn this into cURL syntax for PHP.
problem right there, and will continue to cause problems with methods
which expect PUT to work as designed. It sounds like POST would be a
much more appropriate request for their requirements.
As for your needs - then you probably need to set CURLOPT_INFILESIZE to
zero and CURLOPT_INFILE to null (although I don't know if this will
cause other problems - I've never done it).
If that doesn't work, you need to ask them why their code is sending the
411 response code. They should be able to tell you what's wrong with
your request.
Of course, the correct answer would be for them to not misuse requests
like they are. It sounds like someone looked up what a PUT request was,
and decided "that's neat - let's use it" without really understanding
what it's all about.
here. I have not tried setting the infile size and location to NULL, I
will try, but I am not holding my breath. They did tell me that if I
set the _method to put in the header, I can do this as a POST. I'm
wondering if anyone can advise how to do that. I saw the header
command in the PHP manual, but I'm not certain how to set a value. I
tried
header ("_method : true")
HTTP does not let me set CURLOPT_INFILESIZE and CURLOPT_INFILE to NULL.
Length would be zero, not null. But I didn't know if it would work or not - it's really not what PUT was made for, and I've never tried to use it that way.
One other thing - as for doing it as a POST request - do they mean place the _method=put in the header - or pass it as a POST parameter? I would expect the latter, since _method is not part of the standard headers.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: Problem using cURL with a web service
- From: JustWondering
- Re: Problem using cURL with a web service
- References:
- Problem using cURL with a web service
- From: JustWondering
- Re: Problem using cURL with a web service
- From: Jerry Stuckle
- Re: Problem using cURL with a web service
- From: JustWondering
- Re: Problem using cURL with a web service
- From: Jerry Stuckle
- Re: Problem using cURL with a web service
- From: JustWondering
- Re: Problem using cURL with a web service
- From: JustWondering
- Problem using cURL with a web service
- Prev by Date: Re: [COPIED] PHP 5.3 incompatibilities
- Next by Date: Re: hi
- Previous by thread: Re: Problem using cURL with a web service
- Next by thread: Re: Problem using cURL with a web service
- Index(es):
Relevant Pages
|