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.
For example, automatically generate the corresponding jQuery 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:
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:
Does not appear at the end of the URL:
Base64 encoding of pictures in postman is automatically encoded:
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”: