Found a problem that postman automatically generates interface calling code

Time:2022-5-5

Postman is an interface testing and verification tool often used by programmers.

Click the button below in postman to see the implementation code in different programming languages corresponding to the interface call in code snippet.

Found a problem that postman automatically generates interface calling code

For example, automatically generate the corresponding jQuery Code:

Found a problem that postman automatically generates interface calling code

However, I found that these automatically generated codes can not be directly copied and pasted.

For example, in the above figure, the interface I call with postman uses the HTTP method post

The automatically generated jQuery code, method: post, at first glance also specifies that the HTTP method type is post

But when I paste it into the HTML code, the final method is get instead of the expected post:
Found a problem that postman automatically generates interface calling code

 var settings = {
            "url": "https://aip.baidubce.com/rest/2.0/ocr/v1/taxi_receipt?access_token=335-23882959",
            "method": "POST",
            "timeout": 0,
            "headers": {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            "data": {
              "image": "11",
              "name": "2"
            }
          }
          /*
          $.ajax(settings).done(function (response) {
            console.log(response);
          });*/

After research, the following is the correct way to write, that is, replace “method”: “post” with “type”: “post”

$.ajax({
            type: "POST",
            url: settings.url,
            data: settings.data,
            dataType: "application/x-www-form-urlencoded"
          });

My jQuery version is lower: jQuery / jquery1 7.1. js

The successfully sent HTTP request, with the key of image and the value of 11, is displayed in the chrome developer tool, as shown in the following figure:

form data:

Found a problem that postman automatically generates interface calling code

Does not appear at the end of the URL:
Found a problem that postman automatically generates interface calling code

Found a problem that postman automatically generates interface calling code

Found a problem that postman automatically generates interface calling code

Base64 encoding of pictures in postman is automatically encoded:
Found a problem that postman automatically generates interface calling code

Therefore, when using ABAP to call, we must manually execute the encode action.

If the curl test is used, use — data to specify the load of the request body.

curl -i -k ‘https://aip.baidubce.com/rest…[token obtained by calling authentication interface] ‘– data’ image = [picture Base64 encoding, URLEncode required] ‘- H’ content type: application / x-www-form-urlencoded ‘

More Jerry’s original articles are: “Wang Zixi”:
Found a problem that postman automatically generates interface calling code

Recommended Today

Modify user information changeinfo

When judging the persistence layer: Problem: there is such a problem when modifying user information. For example: the user’s email is not required. It was not empty originally. At this time, the user deletes the mailbox information and submits it. At this time, if it is not empty to judge whether it needs to be […]