我的呼叫代码在VB中而不是C#中:
我需要从VB.net代码调用C#中的api服务并发送3个变量。当我使用此代码时,它会返回错误,因为我认为我在哪里发送变量是不正确的。您能否请我引导我一种从VB发送多个变量以调用服务的正确方法?
这是调用服务的VB方法:
Dim apiUrl As String
apiUrl = ConfigurationManager.AppSettings("URL").ToString()
Dim hwr As HttpWebRequest
hwr = WebRequest.Create(apiUrl + "api/Connect/acc")
Dim postData = "Id =" & objSession.CurrentObject.Object_ID.ToString() & "&UserName =" & name & "&Reason =" & statusReason
hwr.Method = "POST"
Try
Using wr As WebResponse = hwr.GetResponse()
If CType(wr, HttpWebResponse).StatusCode = HttpStatusCode.OK Then
Using dataStream As Stream = wr.GetResponseStream()
Using reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
reader.Close()
End Using
End Using
wr.Close()
End If
End Using
Catch ex As Exception
'...handle error...
End Try
这是正在API中调用的方法:
[RoutePrefix("api/Connect")]
Class
.......
[HttpPost]
[Route("acc")]
public void CancelTransaction(int Id, string UserName, string Reason)
{
...
}