我有一个来自 JNE 的程序员的 restAPI 代码,公司代表送货服务。
他们说这个 API 可以在 POSTMAN(Google Chrome 应用程序)中运行
它在 POSTMAN 中运行良好,在此应用程序中,我只需要插入request URL
(我从 JNE 公司获得的)和两个键和值的标题,如下所示;
KEY VALUE
----------------------------------------------
username mycompany
api key 4534645756864234523424
这样做的方法是POST
,当我发布它时,它给了我预期的结果。
我现在的问题是,如何在我的页面中运行此代码,这样我就不需要在邮递员中运行它。
如果有人可以帮助我解决这个问题,我今天将学习 JSON。
[更新问题1]
{
"version":1,
"collections":
[
{
"id":"c8b12431-8586-cbdd-aef7-056ec177509a",
"name":"asdasdadasdasdasd",
"timestamp":1415593872130,
"requests":
[
{
"collectionId":"c8b12431-8586-cbdd-aef7-056ec177509a",
"id":"d1b2ed66-781d-d02e-c4eb-0416dd3e07a1",
"name":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jak",
"description":"",
"url":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jak",
"method":"POST",
"headers":"username: mycompany\napi_key:089a12ffb8cd5009bdfa4ba5bdb9ee26\n",
"data":
[
{
"key":"username",
"value":"mycompany",
"type":"text"
},
{
"key":"api_key",
"value":"dsfsdfsdfs98d98sdfsdf9898dsfs",
"type":"text"
}
],
"dataMode":"params",
"timestamp":0,
"responses":[],
"version":2
}
]
}
],
"environments":[],
"headerPresets":[],
"globals":[]
}
从上面的更新问题;我的第一个问题是:]
我必须以什么格式保存这个文件:JSON?或者是什么?
我应该将此文件与我的网页一起保存在一个文件中吗?或者我可以将它保存为外部文件吗?
从上面的代码中,我得到如下结果:
{
"detail": [
{
"code": "CGK10000",
"label": "JAKARTA"
},
{
"code": "CGK10100",
"label": "JAKARTA BARAT"
},
{
"code": "CGK10300",
"label": "JAKARTA PUSAT"
},
{
"code": "CGK10200",
"label": "JAKARTA SELATAN"
},
{
"code": "CGK10500",
"label": "JAKARTA TIMUR"
},
{
"code": "CGK10400",
"label": "JAKARTA UTARA"
}
]
}
如果您查看"label"
它是从以下最后一个字符串的键生成的:"name":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jak",
最后一个字符串 , 的标签结果jak
是我想要插入到下拉 html 标记中的内容,用户将在其中选择它(位置名称)。
[更新完整代码]
POST /tracing/mycompany/origin/key/jak HTTP/1.1
Host: api.jne.co.id:8889
Content-Type: application/json
username: mycompany
api_key: 089a12ffb8cd5009bdfa4ba5bdb9ee26
{
"version":1,
"collections":
[
{
"id":"c8b12431-8586-cbdd-aef7-056ec177509a",
"name":"asdasdadasdasdasd",
"timestamp":1415593872130,
"requests":
[
{
"collectionId":"c8b12431-8586-cbdd-aef7-056ec177509a",
"id":"d1b2ed66-781d-d02e-c4eb-0416dd3e07a1",
"name":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jakarta",
"description":"",
"url":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jakarta",
"method":"POST",
"headers":"username: mycompany\napi_key:089a12ffb8cd5009bdfa4ba5bdb9ee26\n",
"data":
[
{
"key":"username",
"value":"mycompany",
"type":"text"
},
{
"key":"api_key",
"value":"089a12ffb8cd5009bdfa4ba5bdb9ee26",
"type":"text"
}
],
"dataMode":"params",
"timestamp":0,
"responses":[],
"version":2
}
]
}
],
"environments":[],
"headerPresets":[],
"globals":[]
}
我已将此文件另存为jne.json
,jne.html
但浏览器仅显示完整的代码 insted 显示结果,如邮递员所做的那样。我认为我在这里缺少很多东西。