- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试使用 HTTP 协议(protocol)获取 OrientDb
数据库的列表。但是我无法得到预期的响应,我可以在浏览器中获得。
如果我在浏览器地址行中输入 http://localhost:2480/listDatabases
那么我有回应:
{"@type":"d","@version":0,"databases":["MaximDB","GratefulDeadConcerts"],"@fieldTypes":"databases=e"}
如何使用 golang
获得相同的结果?
我的代码:
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
client := &http.Client{}
req, err := http.NewRequest("GET", "http://localhost:2480/listDatabases", nil)
req.SetBasicAuth("root", "1")
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Error : %s", err)
}
fmt.Println("resp")
fmt.Println(ToJson(resp))
}
func ToJson(obj interface{}) string {
b, err := json.MarshalIndent(&obj, "", " ")
if err != nil {
fmt.Printf("Error : %s", err)
}
strJson := string(b)
return strJson
}
控制台输出:
resp
{
"Status": "200 OK",
"StatusCode": 200,
"Proto": "HTTP/1.1",
"ProtoMajor": 1,
"ProtoMinor": 1,
"Header": {
"Connection": [
"Keep-Alive"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Date": [
"Fri Jun 05 22:19:23 MSK 2015"
],
"Etag": [
"0"
],
"Server": [
"OrientDB Server v.2.0.10 (build UNKNOWN@r; 2015-05-25 16:48:43+0000)"
],
"Set-Cookie": [
"OSESSIONID=-; Path=/; HttpOnly"
]
},
"Body": {},
"ContentLength": -1,
"TransferEncoding": null,
"Close": false,
"Trailer": null,
"Request": {
"Method": "GET",
"URL": {
"Scheme": "http",
"Opaque": "",
"User": null,
"Host": "localhost:2480",
"Path": "/listDatabases",
"RawQuery": "",
"Fragment": ""
},
"Proto": "HTTP/1.1",
"ProtoMajor": 1,
"ProtoMinor": 1,
"Header": {
"Authorization": [
"Basic cm9vdDox"
]
},
"Body": null,
"ContentLength": 0,
"TransferEncoding": null,
"Close": false,
"Host": "localhost:2480",
"Form": null,
"PostForm": null,
"MultipartForm": null,
"Trailer": null,
"RemoteAddr": "",
"RequestURI": "",
"TLS": null
},
"TLS": null
}
最佳答案
您的请求很好,这是您尝试打印响应的方式。
您正在将整个响应对象编码为 JSON,您可以看到 "Body": {},
缺少您的正文。 *http.Response
不会按照您想要的方式编码为 JSON。这是因为 Body
字段不仅仅是一个 string
或 []bytes
,它是一个 io.ReadCloser
。并且 JSON 编码代码不会对其调用 .Read
。
尝试其中之一来获取响应正文
var b bytes.Buffer
_, err = b.ReadFrom(resp.Body)
if err != nil {
log.Fatal("Error : %s", err)
}
fmt.Println(b.String())
或
contents, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal("Error : %s", err)
}
fmt.Println(string(contents))
或者要获得额外的响应元信息,您可以这样做
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
log.Fatal("Error : %s", err)
}
fmt.Println(string(dump))
(第二个标志 true
表示包含正文,否则它只会显示状态和标题)
关于go - 使用 HTTP 协议(protocol)和 golang 列出 OrientDb 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30673437/
我对 OrientDB 中的多重继承很好奇...假设我创建了以下顶点类: CREATE CLASS A EXTENDS V CREATE PROPERTY A.label STRING CREATE
generic 类和vertex 或edge 类有什么区别?你为什么要用一个而不是另一个? 最佳答案 OrientDB 是一个多模型数据库。文档中介绍了数据建模: http://orientdb.co
如何在 Orientdb 中使 Edge 独一无二。 我想出的解决方案: 删除边 重新创建 但这并不好。 Edge 没有任何属性。 示例: create edge is_friend from #12
这是我现在使用的查询: INSERT INTO details SET name = "INITIALIZE",actionMap ={"1":12:1,"2":12:2}; 这里 12:1,12:2
考虑我们有 Vertex User 和 Edge FriendsWith。FriendsWith 可以在两个方向上进出(通常是在 2 个用户之间或在 2 个用户之间)。 重复是指从一个用户到另一个用户
是否可以删除 OrientDB 文档中嵌入列表中的一项?我有一个“个人数据”文档,其中包含“查询”列表。例如 { name: "Marco", inquiries: [{date: 2014-11-2
我想查询具有特定属性的文档。 我尝试了以下方法: select * from Foo where not bar is null 但这会返回我的文档,即使它们没有该属性。即使它可以工作,但如果存在以
我的问题是,我如何查询“聊天”表以检索个人资料表中的人员详细信息。 ParticipatinIn edge 从 Person 开始聊天。HasProfile Edge 开始了个人资料。 请帮我解决这个
我想查询具有特定属性的文档。 我尝试了以下方法: select * from Foo where not bar is null 但这会返回我的文档,即使它们没有该属性。即使它可以工作,但如果存在以
是否有可能得到一个例子来在 orientdb 中插入一条边。如果它不存在,有没有办法检查边是否存在,如果存在则只更新边,否则创建新边。我使用的是 Orientdb 2.1.13 版本。谢谢 最佳答案
我试图让 OrientDB Studio 显示一个字符串作为每个节点的标签,就像 Susheel Kumar 的这个截图一样 但是,当我运行 Susheel 的代码(为后代发布在下面)时,节点全部显示
我有一个相当复杂的查询 SELECT FROM ( SELECT EXPAND(INV()) FROM ( SELECT FROM ( SELECT EXPAND(OUTE('
我猜这是一个令人尴尬的初学者问题,无论如何... 在“服务器安全”下的 OrientDB 文档中,我们发现: While OrientDB Server can function as a regul
我有一个 CSV 文件,有 Id1 和 Id2。 Id1 和 Id2 是两个不同类的顶点。我想在 Id1 和 Id2 之间取得优势。这可以通过ETL实现吗? 我们可以在变压器的边缘配置中添加一些东西来
我正在研究 OrientDB 进行学术研究。我们应该关注的一个重要部分是 ACID 范式。 OrienDB 手册说: OrientDB is an ACID compliant DBMS. 它还说:
我正在使用 OrientDB 2.1.9 并创建了名为“TimespentEvents”的 plocal 图数据库。 当尝试在同一台机器上使用 JDBC 驱动程序从 Java 连接 URL 'jdbc
我想在 OrientDB 中使用蓝图和管道。 方法是什么?还有 TinkerPop3 或 TinkerPop2?哪个更适合我的学习体验? 最佳答案 OrientDB 的最新版本在本地实现了 Bluep
我一直在尝试使用 OrientDB 提供的“工作室”将 gremlin 与 OrientDB (V 3.0.30) 一起使用,但每次我尝试运行 gremlin 查询,例如 g.V我收到错误:com.o
昨天我们的 nexus 存储库实例由于磁盘已满事件而横盘整理。释放一些空间并尝试重新启动后,nexus 不再可用。结果,数据库损坏(大概)并且无法连接。当我运行 nexus-orient-consol
我正在使用带有 OrientDb Studio 2.2.8 的车辆历史数据库,并且我想要投影 automobile 类由 起亚。 数据库的架构如下所示: (汽车)--isModel-->(型号)--i
我是一名优秀的程序员,十分优秀!