首页 新闻 会员 周边 捐助

请问POST数据返回乱码是什么问题

0
悬赏园豆:10 [已关闭问题] 关闭于 2024-04-06 11:41
protected void Page_Load(object sender, EventArgs e)
{
    //采集地址 https://www.fullgoal.com.cn/PCF/html/PCF21/index.html?fundCode=513870

    string date = "2024-04-01";
    string url = "https://www.fullgoal.com.cn/pcfapi/fullgoal_qryPCF21";
    string post = String.Empty;
    if (true)
    {
        var param = new { fundCode = code, fileDate = date.Replace("-", ""), t = "2024-04-05T13:08:45.721Z" };
        string str = JsonConvert.SerializeObject(param);
        string md5 = TextHelper.MD5(str).ToLower();
        byte[] utf8 = Encoding.UTF8.GetBytes(str);
        string base64 = Convert.ToBase64String(utf8);
        post = String.Format("data={0}{1}{2}", md5.Substring(0, 10), base64, md5.Substring(md5.Length - 5, 5));
    }

    Dictionary<string, string> dict_head = new Dictionary<string, string>
        {
            { "Content-Type", "application/x-www-form-urlencoded" },
            { "Accept", "application/json" },
            { "x-mas-app-info", "1234567/public" }
        };

    string res = Shentoo.Framework.HttpHelper.PostUrl(url, post, dict_head);

    Response.Write(res);
}

public static string MD5(string text)
{
    MD5 md5 = new MD5CryptoServiceProvider();
    byte[] md5data = md5.ComputeHash(Encoding.UTF8.GetBytes(text));
    md5.Clear();
    string str = "";
    for (int i = 0; i < md5data.Length; i++)
    {
        str += md5data[i].ToString("x").PadLeft(2, '0');
    }
    return str;
}

/// <summary>
/// Post请求
/// </summary>
public static string PostUrl(string url, string content, Dictionary<string, string> d = null)
{
    using (System.Net.WebClient wc = new System.Net.WebClient())
    {
        wc.Encoding = System.Text.Encoding.UTF8;

        if (d != null)
        {
            foreach (var it in d)
                wc.Headers.Add(it.Key, it.Value);
        }

        try
        {
            return wc.UploadString(url, content);
        }
        catch (Exception e)
        {
            throw new ArgumentNullException("value", url + "|" + content + "|" + e.Message);
        }
    }
}

搞了一天,第一次碰到这种问题,是哪个环节出了问题

菜菜灰的主页 菜菜灰 | 初学一级 | 园豆:88
提问于:2024-04-06 10:53
< >
分享
所有回答(1)
0

可能是响应的内容被加密了

dudu | 园豆:30778 (高人七级) | 2024-04-06 12:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册