2

Given the following curl will post to my server, what would the equivalent Ruby code that I can use in my automation scripts? I reviewed this post What is the Ruby equivalent to this curl request? but it would be nice to know the curb syntax equivalent for curl's -u admin:admin ... This curl posts successfully

curl -u admin:admin -F":operation=import" -F":contentType=json" -F":name=sample" -F":content={ 'jcr:primaryType': 'nt:unstructured', 'propOne' : 'propOneValue', 'childOne' : { 'childPropOne' : true } }" http://localhost:4502/content/michigan-lsa/stats/en/people/person/jcr%3Acontent

This this ruby code gives a 500 error. Any pointers would be much appreciated

def postProfileContent
   @profilePath = "http://localhost:4502/content/michigan-lsa/#{@dept}/en/people/#{@category}/#{@uniqueName}/jcr%3Acontent"
   c = Curl::Easy.new
   c.url = "#{@profilePath}"
   c.verbose = true
   c.http_auth_types = :basic
   c.username = "admin"
   c.password = "admin"
   c.enable_cookies = true
   c.follow_location = true
   puts c.cookies
   ask "FINISHED: HTTP #{c.response_code}"
   #set post
   c.http_post("#{@profilePath}",@jsonContent.to_json)
   ask "FINISHED: HTTP #{c.response_code}"
end  
Community
  • 1
  • 1
Cris Rockwell
  • 904
  • 2
  • 16
  • 30
  • 1
    a `500` error means an issue on the server side. It's an `Internal server error`. your using the right syntax to set the username and password. – ptierno Apr 17 '15 at 23:32
  • 1
    You might want to have a look into your server's log file. You should find some information in that file why the server responded with a 500. – spickermann Apr 17 '15 at 23:38
  • 1
    Your code is posting the json as the body whereas your curl snippet is posting a multipart form (of which one field happens to be the data). There are examples of this in the curb readme – Frederick Cheung Apr 18 '15 at 09:53
  • Thanks for the suggestions! There were two probs. I wasn't posting the key/values as Frederick mentioned. Also checking logs I saw and fixed other errors for the import. – Cris Rockwell Apr 18 '15 at 13:32

0 Answers0