Hi Mehdi,
I don't know enough Go to tell if there are problems with your code, but
the rest interface seems to be picky about the headers.
The blurb about the 2 headers below is from
http://www.orientechnologies.com/docs/last/OrientDB-REST.html
I have seen it work without them set, but maybe that's your problem? If you
send the query as the post body, you should not url encode.
All the requests must have these 2 headers:
'Accept-Encoding': 'gzip,deflate'
'Content-Length': <content-length>
On Wednesday, April 8, 2015 at 3:05:08 PM UTC-4, mehdi shams wrote:
>
> Hello,
> i am trying to use OrientDB HTTP interface to work with it from GoLang.
> but i have faced a problem in posting documents to database.
> i have written following code:
> func main(){
>
> fmt.Println("starting")
> answ := putDoc("http://localhost:2480/document/tt",
> `{"name":"foo","age":20}`)
> fmt.Println("answer is", answ)
>
>
> }
>
> func putDoc(url,cont string) string{
> client := &http.Client{}
> req, err := http.NewRequest("POST", url, bytes.NewBufferString(cont))
> req.SetBasicAuth("root", "admin123")
> req.Header.Set("Content-Type","application/json");
>
> resp, err := client.Do(req);
> if err != nil{
> panic(err)
> }
> defer resp.Body.Close()
>
> body, err := ioutil.ReadAll(resp.Body)
>
> return string(body)
> }
>
> but it gives this error:
>
> com.orientechnologies.orient.core.exception.OSerializationException: Error
> on un
> marshalling JSON content: content is null
>
> i tried to set Content-Type to text/plain and also to work with structs
> and Marshall it into post data but still the same problem.
> then I tried it in nodejs and used following code:
>
> var Client = require('node-rest-client').Client;
> var options_auth={user:"root",password:"admin123"};
> client = new Client(options_auth);
> cont = {
> name: "foo",
> age: 25
> }
> client.post("http://localhost:2480/document/tt", cont,
> function(data,response) {
> console.log(data);
> });
>
> and the same problem.
> strangley enough this curl command work perfectly:
> curl -POST -u root:admin123 -d "{'name':'foo', 'age':10}"
>
> another option i tried was to use url-encoded-form-data with url.values in
> golang but the same problem .....
>
> is it really broken? or where I am doing something wrong?
> thanks in advance
>
--
---
You received this message because you are subscribed to the Google Groups
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.