我有以下页面来启动API调用,但我需要知道是否可以通过操作方法而不是直接从我的视图进行此调用。我需要从肌动蛋白方法调用API,原因如下: -
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Save Asset Form</title>
<link href="/style/api-style.css" type="text/css" rel="stylesheet">
</head>
<body>
@using (Html.BeginForm(
null, null, FormMethod.Post, new { @action = "http://win-spdev:8400/servlets/AssetServlet" }
))
{
<table width="650" bgcolor="#FFFFFF" cellpadding="5" cellspacing="0" style="border:1px #ccc solid" align="center">
<tr>
<th colspan="4">Save Asset Form</th>
</tr>
<tr>
<td align="right" width="142">Name</td>
<td><input type="text" class="txt" NAME="assetName" style="width:160px;" /></td>
<td width="142" align="right">Asset Type</td>
<td><input type="text" class="txt" NAME="assetType" value="" style="width:160px;" /></td>
</tr>
//code goes here..............................................................
<td align="right" width="142">Associate To Department</td>
<td><input type="text" class="txt" NAME="associateToDepartment" style="width:160px;" /></td>
<td width="142" align="right">Associate To User</td>
<td><input type="text" class="txt" NAME="associateToUser" value="" style="width:160px;" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="4">
<table class="innertable" cellpadding="5" cellspacing="0" width="100%">
<tr>
<td class="thd" colspan="4">Authentication details</td>
</tr>
<tr>
<td align="right" width="142">username</td>
<td><input type="text" class="txt" NAME="username" style="width:160px;" /></td>
<td width="142" align="right">password</td>
<td><input type="password" class="txt" NAME="password" value="" style="width:160px;" /></td>
</tr>
<tr>
<td align="right" width="142">domain</td>
<td><input type="text" class="txt" NAME="DOMAIN_NAME" style="width:160px;" /></td>
<td align="right" width="142">Authentication Mode</td>
<td><INPUT TYPE=radio NAME="logonDomainName" value="Local Authentication" >Local Authentication
<INPUT TYPE=radio NAME="logonDomainName" value="AD_AUTH" >AD Authentication</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="4" height="10"></td>
</tr>
<tr>
<td align="center" colspan="4" class="footer"><input type="submit" name="operation" value="SaveAsset" class="btnsubmitact"></td>
</tr>
</table>
}
我需要将调用记录到我自己的数据库中,因此在完成API调用后,我需要使用API状态(成功或失败)记录调用。
我需要操纵返回XML并显示更加用户友好的错误消息,或者即使API调用怀疑我想用我的asp.net mvc重定向到动作方法。
关于如何将API调用从我的视图转换为我的操作方法的任何建议?
答案 0 :(得分:1)
我需要知道是否可以通过操作方法而不是直接从我的视图
进行此调用
是的,您只需启动HttpWebRequest并从您的操作中发送它,或者如果只是一个简单的请求,请使用WebClient。