我必须使用javascript实现它。
我有这堂课:
Public Class RecommendedJobsData Public Property searchedJobsList As List(Of JobInfo) Public Property jobFromStorage As JobInfo Public Property totalJobsCount As Integer Public Property adType As AdType Public Sub New() ' default constructor End Sub ' constructor with parameters Public Sub New(searchedJobsList As List(Of JobInfo), jobFromStorage As JobInfo, totalJobsCount As Integer, adType As AdType) Me.searchedJobsList = searchedJobsList Me.jobFromStorage = jobFromStorage Me.totalJobsCount = totalJobsCount Me.adType = adType End Sub End Class我正在尝试向此函数发送一个帖子请求:
<JsonpFilter()> Public Function GetToken(header As RequestHeader, body As RecommendedJobsData) As String Return String.Empty End Function所以我使用了javascript:
var http = new XMLHttpRequest(); http.open("POST", url, true); //Send the proper header information along with the request http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.onreadystatechange = function () {//Call a function when the state changes. if (http.readyState == 4 && http.status == 200) { alert(http.responseText); } } http.send(apiParams);标题传递正常,但身体不是..
它进入默认构造函数而不是获取参数的构造函数,然后, GetToken函数的body对象中有null值。
这是apiParams:
任何帮助赞赏!
I had to implement it using javascript.
I have this class:
Public Class RecommendedJobsData Public Property searchedJobsList As List(Of JobInfo) Public Property jobFromStorage As JobInfo Public Property totalJobsCount As Integer Public Property adType As AdType Public Sub New() ' default constructor End Sub ' constructor with parameters Public Sub New(searchedJobsList As List(Of JobInfo), jobFromStorage As JobInfo, totalJobsCount As Integer, adType As AdType) Me.searchedJobsList = searchedJobsList Me.jobFromStorage = jobFromStorage Me.totalJobsCount = totalJobsCount Me.adType = adType End Sub End ClassI am trying to send a post request to this function:
<JsonpFilter()> Public Function GetToken(header As RequestHeader, body As RecommendedJobsData) As String Return String.Empty End FunctionSo I used javascript:
var http = new XMLHttpRequest(); http.open("POST", url, true); //Send the proper header information along with the request http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.onreadystatechange = function () {//Call a function when the state changes. if (http.readyState == 4 && http.status == 200) { alert(http.responseText); } } http.send(apiParams);The header is passed fine, but the body is not..
It enters the default constructor instead of the constructor that gets parameters, and then, there are null values in the body object of GetToken function.
This is apiParams:
Any help appreciated!
最满意答案
我已将内容类型更改为:
http.setRequestHeader("Content-type", "application/json");然后我改变了发送功能:
http.send(JSON.stringify(apiParams));最重要的是:
GetToken函数中的<FromBody()>属性:
Public Function GetToken(header As RequestHeader, <FromBody()> body As RecommendedJobsData)请注意添加对system.web.http的引用。
I have changed the content-type to be:
http.setRequestHeader("Content-type", "application/json");And then I changed the send function:
http.send(JSON.stringify(apiParams));And the most important thing is:
<FromBody()> attribute in GetToken function:
Public Function GetToken(header As RequestHeader, <FromBody()> body As RecommendedJobsData)Note to add a reference to system.web.http.
更多推荐
发布评论