我可以使用表单仅发布json字符串(不带"name =")吗? [英] can I post json string only (without "name=") using form?

查看:141
本文介绍了我可以使用表单仅发布json字符串(不带"name =")吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将json数据发布到我无法控制的URL. API文档说仅接受json数据.我在考虑是否可以使用html表单来简化它.

I am trying to post json data to an URL which I have no control. The API document says only json data is accepted. I am thinking whether I can use html form to make it easier.

关于如何使用表单发布json数据",这里有很多文章,但没有一篇适用于我的情况.据我所知,问题是,如果您使用表单发布数据,则发布的内容始终为名称=值",但是,API仅需要值".这就是说,即使我可以将JSON.stringify input的值转换为JSON字符串,我仍然需要使用API​​不需要的名称"来发布它.所以这是我的问题,我真的可以仅使用表单发布值吗?

There are lots of posts here in regards of how to "post json data using form", none of them applies my situation. The problem is, as far as I know, if you post data using form, the thing being post is always "name=value", however, the API wants only "value". That is to say, even though I can JSON.stringify input values to a JSON string, I still need to post it with a "name", which the API doesn't want. So this is my question, can I actually post values only using form?

更新: API文档

API中的内容对我来说很模糊.关键信息是: 1)调用接口时,使用HTTPS协议和JSON数据包,该数据包不需要加密.

What it says in the API is very vague to me. Key infos are: 1)When calling the interface, use HTTPS protocal and JSON data package, the data package doesn't need to be encrypted.

2)HTTPS请求方法:POST https://qyapi.weixin.qq.com/cgi-bin /message/send?access_token = ACCESS_TOKEN

2)HTTPS request method: POST https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN

对于ACCESS_TOKEN,我需要使用一些密码来获取它,并且它会在2小时后失效.

For ACCESS_TOKEN I need to get it using some password and it expires in 2 hours.

3)如果消息发送成功,它将返回:

3)If message sent successfully, it returns:

{
   "errcode": 0,
   "errmsg": "ok",
   "invaliduser": "UserID1",
   "invalidparty":"PartyID1",
   "invalidtag":"TagID1"
}

推荐答案

否.允许直接从表单中直接生成JSON格式的数据的工作停产.

要发出请求,您将需要使用以下任一方法:

To make the request you will need to use either:

  • XMLHttpRequest to the API (which requires that permission, including support for a preflight, is granted by the API)
  • XMLHttpRequest to a proxy
  • Server side code

其中任何一个都可以使用HTML表单来收集数据,然后再使用它来生成对第三方API的请求.

Any of these could use an HTML form to collect the data before using it to generate the request to the third party API.

这篇关于我可以使用表单仅发布json字符串(不带"name =")吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆