Re: Problem using cURL with a web service



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:
On May 21, 4:20 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
JustWondering wrote:
First, a question: The cURL manual says that TCURLOPT_INFILE and
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)?
The PUT request is used to upload resources to the server. So you must
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.
I am not trying to upload anything. This web service decided that they
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.
So they're using PUT contrary to the design of the request. That's a
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.
I've fired off some emails, telling them pretty much what you say
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
==================
.



Relevant Pages

  • Re: Problem using cURL with a web service
    ... I did try to use PUT with a web service that requires it. ... have some resource to upload. ... much more appropriate request for their requirements. ... since _method is not part of the standard headers. ...
    (comp.lang.php)
  • Re: File Post Control
    ... think that by changing the content-length property in a header you will make ... I am using file post control to upload a large file to web server. ... Now what this control do is that it will reject any such request ... and keep on rejecting th eread portion from memory. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Posting SOAP messages with Msxml2.ServerXMLHTTP.4.0
    ... particular web service and its WSDL for instance can tell you what header you have to set (for a particular request). ...
    (microsoft.public.scripting.jscript)
  • Web Service call times out under IIS 5.1
    ... I have code which makes web service calls from within one web application to ... the last month) this has stopped working under IIS 5.1 for no obvious reason. ... Inspecting the call using tcptrace shows the header is being sent but not ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Asynchronous Web Service Call
    ... I think I understand your request so here goes.... ... How is the request handled from a consumer perpective? ... stage later when the web service process is complete, ... The background of my question adresses server to ...
    (microsoft.public.dotnet.framework.aspnet.webservices)