4

好的,问题如下。我必须从在线表格中获取信息,然后再次提交(更改)。该页面位于“windows-1251”中,在我的请求中,我得到了它:

{
         // used to build entire input
        StringBuilder sb = new StringBuilder();

        // used on each read operation
        byte[] buf = new byte[8192];

        // prepare the web page we will be asking for
        HttpWebRequest request = (HttpWebRequest)
            WebRequest.Create(url);

        // execute the request
        HttpWebResponse response = (HttpWebResponse)
            request.GetResponse();

        // we will read data via the response stream
        Stream resStream = response.GetResponseStream();

        string tempString = null;
        int count = 0;

        do
        {
            // fill the buffer with data
            count = resStream.Read(buf, 0, buf.Length);

            // make sure we read some data
            if (count != 0)
            {
                // translate from bytes to ASCII text
                tempString = Encoding.GetEncoding(1251).GetString(buf, 0, count);

                // continue building the string
                sb.Append(tempString);
            }
        }
        while (count > 0); // any more data to read?

        // print out page source
        // Console.WriteLine(sb.ToString());
        return sb.ToString();

所以在那之后我剥离页面并将我的数据放入一个数组中,我需要再次将其发布到站点,但它需要进行编码。我使用 System.Net.WebUtility.UrlEncode 进行编码,但我的脚本和 firefox 得到了完全不同的结果(我使用篡改数据得到了原始结果)。因此,任何帮助或想法都会受到赞赏。顺便说一句,在我获得编码数据(来自脚本)后,我在http://www.url-encode-decode.com/上在线尝试了它,只有 UTF-8 返回了正确的结果。所以我猜我必须将它转换为 1251 并且我尝试这样做,但它仍然是胡言乱语并且与它应该是完全不同的......所以请如果你能帮助我它会很棒......: )

编辑:

Expected: %E3%F0%E0%E4+%D1%EE%F4%E8%FF
Actual: %D0%B3%D1%80%D0%B0%D0%B4+%D0%A1%D0%BE%D1%84%D0%B8%D1%8F
f2[11] = град София
-       f2  {string[180]}   string[]
    [0] "127.0.0.1" string
    [1] "1348247257"    string
    [2] "1n132135075318435" string
    [3] "151669n1"  string
    [4] "0" string
    [5] null    string
    [6] null    string
    [7] null    string
    [8] "2" string
    [9] "12871449760521116" string
    [10]    "14"    string
    [11]    "град София"    string
    [12]    "Враждебна" string
    [13]    "42.707984,23.41341,0~бул. Ботевградско шосе"   string
    [14]    "42.7100653,23.4274006,1"   string
4

1 回答 1

4
于 2012-09-24T07:53:14.653 回答