巴格梅 2019-02-21 15:00 采纳率: 0%
浏览 321

关于http通信的一些问题:请问大佬第一句的字符串各个部分都是什么意思

private const string UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3";

public static string PostData(string url, string data)
{
    // Convert to bytes
    string strReturn = "";
    try
    {
        byte[] obtPostData = Encoding.UTF8.GetBytes(data);
        HttpWebRequest orqRequest = (HttpWebRequest)WebRequest.Create(url);
        orqRequest.Timeout = 3000;
        orqRequest.Method = "POST";
        orqRequest.UserAgent = UserAgent;
        orqRequest.ContentType = "application/x-www-form-urlencoded";
        orqRequest.ContentLength = obtPostData.Length;
        orqRequest.AllowAutoRedirect = false;
        // Add post data to request
        Stream stream;
        using (stream = orqRequest.GetRequestStream())
        {
            stream.Write(obtPostData, 0, obtPostData.Length);
        }
        HttpWebResponse orsResponse = (HttpWebResponse)orqRequest.GetResponse();
        using (Stream responseStream = orsResponse.GetResponseStream())
        {
            using (StreamReader streamRead = new StreamReader(responseStream, Encoding.UTF8))
            {
                strReturn = streamRead.ReadToEnd();
            }
        }
    }
    catch (Exception e)
    {
        strReturn = e.Message;
    }
    return strReturn;
}
  • 写回答

1条回答 默认 最新

  • threenewbee 2019-02-21 15:11
    关注

    ua字符串,原本是为了向服务器报告自身使用的软件环境。但是现代浏览器为了兼容,往往会把自己伪装成全能的浏览器。所以这东西意义不大了。你就知道这个是xp上的firefox就可以了。

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条