所以我现在要查看ServiceNow的附件API,文档如下:
https://docs.servicenow.com/integrate/inbound_rest/reference/r_AttachmentAPI-POST.html
对于我正在开发的应用程序,我需要编写一些Perl代码来处理附件。不幸的是,ServiceNow Perl API库不能处理大于5mb的附件,因此我需要使用实例附带的stock附件API。
在上面的链接中,我看到了一个关于如何用这个python代码发布文件的示例。
#Need to install requests package for python
#easy_install requests
import requests
# Set the request parameters
url = 'https://instance.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=d71f7935c0a8016700802b64c67c11c6&file_name=Issue_screenshot.jpg'
# Specify the file To send. When specifying fles to send make sure you specify the path to the file, in
# this example the file was located in the same directory as the python script being executed.
data = open('Issue_screenshot.jpg', 'rb').read()
# Eg. User name="admin", Password="admin" for this code sample.
user = 'admin'
pwd = 'admin'
# Set proper headers
headers = {"Content-Type":"image/jpeg","Accept":"application/json"}
# Do the HTTP request
response = requests.post(url, auth=(user, pwd), headers=headers, data=data)
# Check for HTTP codes other than 201
if response.status_code != 201:
print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
exit()
# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)
我经常使用REST::Client来发帖,但是不幸的是,我找不到一个很好的例子来说明如何处理上面的^^^但是在Perl中。如何使用REST::Client来发布上述文件?
我通过调用
curl
在我的脚本中,但是使用REST::Client会更优雅。