can I post json string only (without “name=”) using form?

我只是一个虾纸丫 提交于 2020-01-11 11:34:26

问题


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.

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?

Update: the API document

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 request method: POST https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN

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

3)If message sent successfully, it returns:

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

回答1:


No. The work to allow JSON formatted data to be directly generated from a form has been discontinued.

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

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



来源:https://stackoverflow.com/questions/38022158/can-i-post-json-string-only-without-name-using-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!