我正在尝试从此页面https://www.bddk.org.tr/BultenHaftalik中获取一些数据。(您可以输入/ en以英语查看) (不好意思我的英语不好)
但是我需要发布带有某些参数的__RequestVerificationToken。
我创建了一个简单的GET函数来获取cookie值并将其定向到提供Post参数的方法,但是我的响应内容是:
{"Baslik":"Grafik Başlığı","XEkseni":[],"YEkseni":[]}
该网站上的AJAX是:
function VeriGetir(id, para, sutun, gun, tarafKodu ) {
if (myChart != undefined) {
myChart.destroy();
}
$.ajax({
url: "/BultenHaftalik/tr/Home/KiyaslamaJsonGetir",
type: 'POST',
data: {/* __RequestVerificationToken: token, */"dil":'tr', "tarih": '8.3.2019', "id": id, "parabirimi": para, "sutun": sutun, "tarafKodu": tarafKodu ,"gun":gun },
success: function (result) {
Graph(result.Baslik, result.XEkseni, result.YEkseni);
$("#ModalBaslik").text(result.Baslik);
}
});
在顶部的代码中:
Private HaftalikTaylan As State = New State With {.Url = "http://www.bddk.org.tr/BultenHaftalik/"}
Private __RequestVerificationToken As String = String.Empty
Private HaftalikTaylan_post As State = New State With {.Url = "http://www.bddk.org.tr/BultenHaftalik/tr/Home/DonemDegistir/"}
方法类似于:
Private Sub Deneme()
Dim client As RestSharp.RestClient = New RestSharp.RestClient(Me.HaftalikTaylan.Url)
Me.HaftalikTaylan.Request = New RestSharp.RestRequest(RestSharp.Method.GET) With {.Timeout = 5 * 60 * 1000}
Me.HaftalikTaylan.Response = client.Execute(Me.HaftalikTaylan.Request)
If Me.HaftalikTaylan.Response.Cookies.Count > 0 Then
For i As Integer = 0 To Me.HaftalikTaylan.Response.Cookies.Count - 1
If Me.HaftalikTaylan.Response.Cookies(i).Name.Contains("__RequestVerificationToken_L0J1bHRlbkhhZnRhbGlr0") Then
__RequestVerificationToken = Me.HaftalikTaylan.Response.Cookies(i).Value
End If
Next
End If
Me.Deneme_post(__RequestVerificationToken)
End Sub
Private Sub Deneme_post(__RequestVerificationToken As String)
Me.ExtractClear()
Dim client As RestSharp.RestClient = New RestSharp.RestClient(Me.HaftalikTaylan_post.Url)
Me.HaftalikTaylan_post.Request = New RestSharp.RestRequest(RestSharp.Method.POST) With {.Timeout = 5 * 60 * 1000}
Me.HaftalikTaylan_post.Request.AddHeader("cahce-control", "no-cache")
Me.HaftalikTaylan_post.Request.AddHeader("content-type", "application/x-www-form-urlencoded")
Dim parameterString As String = "__RequestVerificationToken=" & __RequestVerificationToken & "&dil=tr&tarih=8.3.2019&id=154¶birimi=TL&sutun=154&tarafKodu=10001&gun=90"
Me.HaftalikTaylan_post.Request.AddParameter("application/x-www-form-urlencoded", parameterString, RestSharp.ParameterType.RequestBody)
Me.HaftalikTaylan_post.Response = client.Execute(Me.HaftalikTaylan_post.Request)
End Sub
谢谢。