[英]Unexpected return value from function
長期潛伏,第一次海報。
我正在編寫一個WEBAPI,並且對默認輸出有一些疑問。 我知道輸出基於請求中的ACCEPT(json / xml等)。 但是,我需要完全控制輸出。 我將格式化自己的XML。
我已經找到了幾個有關如何執行此操作的示例,大多數在.cs中,因此我嘗試將其更改為vb.net。
這是我的測試之一:
Public Function Authenticate() As HttpResponseMessage
Dim XML As String = "Message content"
Return New HttpResponseMessage() With { _
.Content = New StringContent(XML, Encoding.UTF8, "application/xml") _
}
End Function
在調用函數中時,當我嘗試時:返回Authenticate()
我收到一個錯誤:無法將類型'System.net.http.httpresponsemessage'的值轉換為String
似乎在.cs中使用了很多,因為我看到了很多示例。 任何人都有在VB.NET中如何實現此目的的想法?
我的控制器:
<HttpGet, HttpPost> _
Public Function [Login](<FromUri> staff As login) As String
Dim xmlheader As String
Dim head As New header
xmlheader = head.addheader()
If staff.password = "" Then
Dim result As String
Dim err As New messages
result = xmlheader & err.geterror("password")
Return Authenticate()
End If
End Function
謝謝!
似乎您正在嘗試將Authenticate的返回值用作字符串。 我不知道您到底想做什么,但是我認為.ToString()
可以工作。
Dim foo As String = Authenticate().ToString()
' Do whatever with foo here...use it as a string
您的問題很清楚。 你有
Public Function [Login](<FromUri> staff As login) As String
您需要聲明您的控制器為
Public Function [Login](<FromUri> staff As login) As HttpResponseMessage
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.