【发布时间】:2020-02-09 08:05:46
【问题描述】:
我知道我的问题看起来像是重复的问题,但我找不到对我的问题有用的解决方案。
所以我正在尝试从货船数据提供网站Link(这是一个韩国网站。右侧的黑色按钮是搜索按钮)抓取数据
但为了从中获取数据,必须设置一些单选按钮然后点击搜索。
我以为我可以通过 FormUrlEncodedContent 传递参数值,然后简单地使用 PostAsync,但不知何故我无法让它们通过。
这是我目前的代码
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded");
var doc = new HtmlAgilityPack.HtmlDocument();
var content = new FormUrlEncodedContent(structInfo.ScriptValues);
var response = await client.PostAsync(structInfo.PageURL, content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
using (WebClient client = new WebClient())
{
var reqparm = new System.Collections.Specialized.NameValueCollection();
reqparm.Add("v_time", "month");
reqparm.Add("ROCD", "ALL");
reqparm.Add("ORDER", "item2");
reqparm.Add("v_gu", "S");
byte[] responsebytes = client.UploadValues("http://info.bptc.co.kr:9084/content/sw/frame/berth_status_text_frame_sw_kr.jsp", "POST", reqparm);
string responsebody = Encoding.UTF8.GetString(responsebytes);
Console.WriteLine(responsebody);
}
我放在 StructInfo 类中的值
PageURL = "http://info.bptc.co.kr:9084/content/sw/frame/berth_status_text_frame_sw_kr.jsp",
ScriptValues = new Dictionary<string, string>
{
{"v_time", "month"},
{"ROCD", "ALL"},
{"ORDER", "item2"},
{"v_gu", "S"}
},
到目前为止,我尝试过的是 HttpClient、WebClient、WebBrowser,但我没有运气。
但奇怪的是,当我尝试使用 Burp Suite 发送帖子时,数据以我想要的方式输出。
过去 4 小时我一直在寻找解决方案,但没有任何运气。
你们愿意帮帮我吗?
谢谢
【问题讨论】:
标签: c# post httpclient