WebClient - 如何在发布内容后获取源代码

时间:2011-10-11 14:15:50

标签: c# .net webclient

我正在使用带有修改过的CookieAwareWebClient类的WebClient。

我希望它如何工作:我使用帖子登录,然后转到我发布类别ID的搜索页面,作为回报,我希望它给我列出类别的网站来源。我已经设法在Python上做到这一点并且工作正常,但在C#上我认为我在这里做错了。

ServicePointManager.Expect100Continue = false;
var client = new CookieAwareWebClient();
client.BaseAddress = @"http://site/";

// Logging in...
// This part works fine
var loginData = new NameValueCollection();
loginData.Add("login", "user");
loginData.Add("pass", "pass");
client.UploadValues("http://site/authorize.html", "POST", loginData);

// Searching for items
// Not so sure about this part since cannot read what is given back
var searchData = new NameValueCollection();
searchData.Add("catName", "tables");
client.UploadValues("http://site/search.html", "POST", searchData);

1 个答案:

答案 0 :(得分:3)

WebClient.UploadValues以字节数组的形式返回响应,但您目前忽略了这一点。这实际上是你想要的数据吗?