Hi,

I'm trying to implement the following REST call (curl command given) to
WSO2 Appfactory in 'GO' using net/http [1] <http://golang.org/pkg/net/http/>
.


*curl -v -c cookies1 -X  POST -k
https://apps.cloud.wso2.com/appmgt/site/blocks/user/login/ajax/login.jag
<https://apps.cloud.wso2.com/appmgt/site/blocks/user/login/ajax/login.jag>
-d 'action=login&userName=<username>&password=<password>' *

The result from this command is as follows.

** Hostname was NOT found in DNS cache*
**   Trying 54.209.187.16...*
** Connected to apps.cloud.wso2.com <http://apps.cloud.wso2.com>
(54.209.187.16) port 443 (#0)*
** successfully set certificate verify locations:*
**   CAfile: none*
*  CApath: /etc/ssl/certs*
** SSLv3, TLS handshake, Client hello (1):*
** SSLv3, TLS handshake, Server hello (2):*
** SSLv3, TLS handshake, CERT (11):*
** SSLv3, TLS handshake, Server key exchange (12):*
** SSLv3, TLS handshake, Server finished (14):*
** SSLv3, TLS handshake, Client key exchange (16):*
** SSLv3, TLS change cipher, Client hello (1):*
** SSLv3, TLS handshake, Finished (20):*
** SSLv3, TLS change cipher, Client hello (1):*
** SSLv3, TLS handshake, Finished (20):*
** SSL connection using ECDHE-RSA-AES256-GCM-SHA384*
** Server certificate:*
** subject: C=US; ST=California; L=Palo Alto; O=WSO2, Inc.;
CN=*.cloud.wso2.com <http://cloud.wso2.com>*
** start date: 2015-05-21 00:00:00 GMT*
** expire date: 2018-06-06 12:00:00 GMT*
** issuer: C=US; O=DigiCert Inc; OU=www.digicert.com
<http://www.digicert.com>; CN=DigiCert SHA2 High Assurance Server CA*
** SSL certificate verify ok.*
*> POST /appmgt/site/blocks/user/login/ajax/login.jag HTTP/1.1*
*> User-Agent: curl/7.35.0*
*> Host: apps.cloud.wso2.com <http://apps.cloud.wso2.com>*
*> Accept: */**
*> Content-Length: 75*
*> Content-Type: application/x-www-form-urlencoded*
*> *
** upload completely sent off: 75 out of 75 bytes*
*< HTTP/1.1 200 OK*
** Server nginx/1.4.6 (Ubuntu) is not blacklisted*
*< Server: nginx/1.4.6 (Ubuntu)*
*< Date: Sun, 21 Jun 2015 08:25:21 GMT*
*< Content-Type: text/html*
*< Content-Length: 5*
*< Connection: keep-alive*
** Added cookie JSESSIONID="************************" for domain
apps.cloud.wso2.com <http://apps.cloud.wso2.com>, path /appmgt/, expire 0*
*< Set-Cookie: JSESSIONID=****************************; Path=/appmgt/;
Secure; HttpOnly*
*< *
*true*
** Connection #0 to host apps.cloud.wso2.com <http://apps.cloud.wso2.com>
left intact*


My code is as follows.

package main

import (
   "bytes"
   "fmt"
   "net/http"
)

func main() {
   client := &http.Client{}
   var query = []byte(`action=login&userName=<username>&password=<password>`)
   r, _ := http.NewRequest("POST",
"https://apps.cloud.wso2.com/appmgt/site/blocks/user/login/ajax/login.jag";,
bytes.NewBuffer(query))
   resp, _ := client.Do(r)
   fmt.Println(resp)
}


The result from running the above code is as follows.

*&{200 OK 200 HTTP/1.1 1 1 map[Server:[nginx/1.4.6 (Ubuntu)] Date:[Sun, 21
Jun 2015 08:38:38 GMT] Content-Type:[text/html] Connection:[keep-alive]
Set-Cookie:[JSESSIONID=5820BCE0F4338F90735C9AFE7ED53B95; Path=/appmgt/;
Secure; HttpOnly]] 0xc208213480 -1 [chunked] false map[] 0xc208026dd0
0xc2081f6060}*

The request fails. I can't seem to find another way to perform this REST
API call. Does anyone know a better way of implementing this request?

[1] http://golang.org/pkg/net/http/

Thanks.
Regards,
Dilhasha


Fathima Dilhasha Nazeer <http://lk.linkedin.com/in/dilhasha/>
(M.N.F.Dilhasha)
Undergraduate | Department of Computer Science and Engineering
University of Moratuwa
Sri Lanka
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to