Turing call API V2 encountered pit

1: The first problem encountered: cross-domain

  

 

 

   Solution:

    The first: Use the query in jsonp

        Unfortunately, Turing requirements of the post method, and jsonp, can only use the get method to cross-domain failure

    The second: server add header, but how do I go and change Turing server failure

    III: By setting Google to solve cross-domain, this is not very rigorous, because on the line, can not use this method

      https://blog.csdn.net/lantingshuxu/article/details/80308028

      solve

2: The second problem encountered: parameter format error, the data returned 4000

        

 

 

   Solution: Convert parameter to json format, not handwritten, you must use JSON.stringify ()

 3: The complete code attached below    

    var obj =  {
                "perception": {
                    "inputText": {
                        "text": "你好"
                    }
                },
                "userInfo": {
                    "apiKey": "自己的机器人key",
                    "userId": "123456"
                },
                
            }
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            url: "http://www.tuling123.com/openapi/api/v2",
            data:JSON.stringify(obj),
            success: function (response) {
                console.log(response);
                
            }
        });

  

    

Guess you like

Origin www.cnblogs.com/wukaiBK/p/11462715.html