can I post json string only (without “name=”) usin

2020-04-19 20: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.