<html>
<head>
</head>
<body>
<h1>Aras</h1>
<span>Item_Number</span><input class="text" type="text" id="Aras-item_number">
<span>Name</span><input class="text" type="text" id="Aras-name">
<span>Description</span><input class="text" type="text" id="Aras-description">
<input class="submit" type="submit" id="Aras-button"value="Aras-button"
onClick="myFun()">
<script type="text/javascript">
function myFun(){
var item_number = document.getElementById("Aras-item_number").value;
var name = document.getElementById("Aras-name").value;
var description = document.getElementById('Aras-description').value;
var xhr = new XMLHttpRequest();
var url = "http://XXX.XXX.XXX.XXX/innovatorserver/server/OData/CAD";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("DATABASE", "InnovatorSolutions");
xhr.setRequestHeader("AUTHUSER", "admin");
xhr.setRequestHeader("AUTHPASSWORD", "XXXXXXXXXXX");
xhr.setRequestHeader("TIMEZONE_NAME", "Taipei Standard Time");
var data = "{\"item_number\": \""+item_number+"\",\"name\":
\""+name+"\",\"description\": \""+description+"\"}";
xhr.send(data);
}
</script>
</body>
</html>
使用HTTP Request要注意的是不能跨網域傳輸,所以必須先將網頁架設在與目標Aras同網域下,IP要一樣,因為前幾天有介紹過如何部屬與架站了,有興趣的朋友可以看(https://ithelp.ithome.com.tw/articles/10216234)
的介紹,所以這邊就不再多做介紹
最後開啟前端顯示畫面,要注意上方的IP必須要和Aras的IP一致,輸入屬性資料後,點選Aras-button案紐後,進入Aras的CAD後就能看到多新增一筆資料了
using System.Text;
using System.Net.Http;
namespace TLTC_WebService.Library
{
public class Connection
{
public void ArasHttpRequest(string item_number, string name, string description)
{
HttpClient client = new HttpClient();
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post,
"http://XXX.XXX.XXX.XXX/innovatorserver/server/odata/CAD");
requestMessage.Headers.Add("DATABASE", "InnovatorSolutions");
requestMessage.Headers.Add("AUTHUSER", "admin");
requestMessage.Headers.Add("AUTHPASSWORD", "XXXXXXXXXX");
requestMessage.Headers.Add("TIMEZONE_NAME", "Taipei Standard Time");
requestMessage.Content = new StringContent("{\"item_number\":
\""+item_number+"\",\"name\": \""+name+"\",\"description\": \""+description+"\"}", Encoding.UTF8, "application/json");
HttpResponseMessage response =
client.SendAsync(requestMessage).GetAwaiter().GetResult();
}
}
}