Cannot send a content-body with this verb-type

前端 未结 4 1478
醉酒成梦
醉酒成梦 2020-11-29 00:32

I just got this exception (ProtocolViolationException) in my .NET 2.0 app (running on windows mobile 6 standard emulator). What confuses me is that as far as i know, I have

4条回答
  •  [愿得一人]
    2020-11-29 01:19

    Because you didn't specify the Header.

    I've added an extended example:

    var request = (HttpWebRequest)WebRequest.Create(strServer + strURL.Split('&')[1].ToString());
    

    Header(ref request, p_Method);

    And the method Header:

    private void Header(ref HttpWebRequest p_request, string p_Method)
    {
        p_request.ContentType = "application/x-www-form-urlencoded";
        p_request.Method = p_Method;
        p_request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE)";
        p_request.Host = strServer.Split('/')[2].ToString();
        p_request.Accept = "*/*";
        if (String.IsNullOrEmpty(strURLReferer))
        {
            p_request.Referer = strServer;
        }
        else
        {
            p_request.Referer = strURLReferer;
        }
        p_request.Headers.Add("Accept-Language", "en-us\r\n");
        p_request.Headers.Add("UA-CPU", "x86 \r\n");
        p_request.Headers.Add("Cache-Control", "no-cache\r\n");
        p_request.KeepAlive = true;
    }
    

提交回复
热议问题