有一个在线表单(https://servizi.ivass.it/RuirPubblica/),您可以在其中进行搜索(只需进行空白搜索)。对于它给出的每个结果,我需要单击结果并导出详细信息页面的第5个表中的列表。
所以基本上我想做一个软件来帮我做到这一点:
当我点击“搜索”按钮时,我用Fiddler检查了POST请求中使用的参数,并尝试用.Net做同样的事情。如果我尝试用HttpClient访问基地址,它会返回正确的搜索表单的超文本标记语言,但当我提交以下带有搜索参数的POST请求时,我得到一个网页,显示错误“警告:会话过期”。
如果我在没有访问主页的情况下单独调用搜索POST,也会发生这种情况,所以我不确定这是否与在两个请求之间保持会话alibe有关。
public MainWindow()
{
InitializeComponent();
var cookieJar = new CookieContainer();
var handler = new HttpClientHandler
{
CookieContainer = cookieJar,
UseCookies = true,
UseDefaultCredentials = false
};
client = new HttpClient(handler)
{
BaseAddress = new Uri("https://servizi.ivass.it/RuirPubblica/Search.faces")
};
}
private async Task TryHttp()
{
// Access the search page
var response = await client.GetAsync(client.BaseAddress);
var responseString = await response.Content.ReadAsStringAsync();
// Perform the search
var values = new Dictionary<string, string>
{
{ "FormSearch", "FormSearch" },
{ "FormSearch:j_id_jsp_558348152_13", "PG" },
{ "FormSearch:j_id_jsp_558348152_16", "custom" },
{ "FormSearch:SecE", "on" },
{ "FormSearch:matricola", "" },
{ "FormSearch:ragioneSociale", "" },
{ "FormSearch:provincia", "NA" },
{ "FormSearch:SearchButton", "Ricerca" },
{ "javax.faces.ViewState", "j_id1:j_id5" },
};
var content = new FormUrlEncodedContent(values);
response = await client.PostAsync(client.BaseAddress, content);
// Here I'm getting a web page showing the error "Warning: Session expired"
responseString = await response.Content.ReadAsStringAsync();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
TryHttp();
}
https://stackoverflow.com/questions/50603727
复制相似问题