Created
May 9, 2017 08:35
-
-
Save flanker/993d3ba3001f5ba03227cc47264b9719 to your computer and use it in GitHub Desktop.
API Test example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>API Test</title> | |
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> | |
</head> | |
<body> | |
<script> | |
// 201 created | |
$.ajax({ | |
type: 'POST', | |
url: 'https://im.jinshuju.com/api/v1/forms/$TOKEN', | |
contentType : 'application/json', | |
data: '{"field_1": "中文测试1"}', | |
beforeSend: function (xhr) { | |
xhr.setRequestHeader ("Authorization", "Basic " + $AUTH_CODE); | |
}, | |
success: function () { | |
alert('OK'); | |
} | |
}); | |
// 201 created | |
$.ajax({ | |
type: 'POST', | |
url: 'https://im.jinshuju.com/api/v1/forms/$TOKEN', | |
contentType : 'application/json', | |
data: JSON.stringify({"field_1": "中文测试2"}), | |
beforeSend: function (xhr) { | |
xhr.setRequestHeader ("Authorization", "Basic " + $AUTH_CODE); | |
}, | |
success: function () { | |
alert('OK'); | |
} | |
}); | |
// 400 bad request | |
$.ajax({ | |
type: 'POST', | |
url: 'https://im.jinshuju.com/api/v1/forms/$TOKEN', | |
contentType : 'application/json', | |
data: {"field_1": "中文测试2"}, | |
beforeSend: function (xhr) { | |
xhr.setRequestHeader ("Authorization", "Basic " + $AUTH_CODE); | |
}, | |
success: function () { | |
alert('OK'); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment