curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Using curllib with PUT to talk to a WS02 server

From: Zakrzewski, Jakub <Jakub.Zakrzewski_at_scheer-group.com>
Date: Thu, 14 Sep 2017 06:16:13 +0000



On 14 Sep 2017 07:52, Frank Durda IV <fdurda.curl_at_why.net> wrote:
(Apologies for possible duplication of this message - cool.haxx.se doesn't
seem to like my local mail MTA)

- - - - -

I have a situation where I have to send a command to a WS02 system
and while I can get the desired results using the curl utility and
its command line parameters, I have been unable to come up with
an equivalent using the curl library.

The command line method (which works fine) is:

curl -v -k --user admin:admin -X PUT -d '{"schemas":[],"userName":"testuser","userType":"0x1234567890abcdef"}' --header "Content-Type:application/json" https://wso2-test.LOCALDOMAIN:9443/wso2/scim/Users/766c1224-b448-422f-90a3-2f39c961d4b0 >& resultfile

While that works, replicating it the library fails with limited clues.
Note that I am able to use the library to communicate with the ws02
server successfully with other operations. The trouble appears to center
around how you pass the json schema (as done with the -d '' parameter
in the command-line version.) Via the curl library, I can direct ws02
to perform a delete operation, eg

         curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,"DELETE");

and that works fine, but that particular conversation doesn't have to
pass the equivalent of -d ''.

There are two bad behaviors. The first is that curl acts like it has
not been supplied with the -d data at all (despite trying a number of
ways listed on this site and on stackoverflow - the data is in a
char * in memory). The second bad behavior is that the library waits
on input from stdin, so the program pauses somewhere inside
curl_easy_perform(). Pressing CTRL-D on the console causes the
curl_easy_perform() to return with a result of zero, and the result
memory buffer contains this response from ws02:

  '{"Errors":[{"code":"400","description":"Request is unparseable, syntactically
incorrect, or violates schema"}]}'

With VERBOSE turned on, you get:

* Trying 10.x.x.x...
* TCP_NODELAY set
* Connected to wso2-test.LOCALDOMAIN (10.x.x.x) port 9443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /usr/local/share/certs/ca-root-nss.crt
   CApath: none
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=US; ST=CA; L=Mountain View; O=WSO2; CN=localhost
* start date: Feb 19 07:02:26 2010 GMT
* expire date: Feb 13 07:02:26 2035 GMT
* issuer: C=US; ST=CA; L=Mountain View; O=WSO2; CN=localhost
* SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> PUT /wso2/scim/Users/766c1224-b448-422f-90a3-2f39c961d4b0 HTTP/1.1
Host: wso2-test.LOCALDOMAIN:9443
Accept: */*
Transfer-Encoding: chunked
Authorization: Basic Yxxxxxxxxxxxxx4=
Content-Type:application/json
Expect: 100-continue

(system pauses here until you type CTRL-D)

< HTTP/1.1 100 Continue
< HTTP/1.1 400 Bad Request
< Cache-Control: private
< Expires: Wed, 31 Dec 1969 18:00:00 CST
< X-Frame-Options: DENY
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Date: Thu, 14 Sep 2017 00:39:08 GMT
< Content-Type: application/json
< Content-Length: 111
< Connection: close
< Server: WSO2 Carbon Server
<
* Closing connection 0

CHG Got back res 0 400
  '{"Errors":[{"code":"400","description":"Request is unparseable, syntactically
incorrect, or violates schema"}]}'

Note that the "Expect: 100-continue" is not something I put in the
headers. Where it is coming from and why is not clear, and I'm pretty
sure it isn't helping.

I don't have access to the ws02 server, so I can't view the conversation
from that end.


Any suggestions? I find contradictory documentation on how to pass
information to accompany the PUT, with some saying not to use one
deprecated function call, while other posts say the newer library call
won't do the job and you have to use the older call.

Thanks in advance for any hints/examples/assistance.


-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html

Have you tried the '--libcurl' parameter to take a peek at generated C code?
Maybe there's the clue you're looking for.

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-09-14