none
服务器提交了协议冲突。Section=ResponseHeader Detail=标头名称无效 RRS feed

  • 问题

  • 代码如下:

     HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://api.XXXX.com/statuses/update.xml");
                myRequest.Method = "POST";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                myRequest.ContentLength = data.Length;
                myRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                myRequest.Headers.Add("Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7");
                myRequest.Headers.Add("Accept-Encoding: gzip, deflate");
                myRequest.Headers.Add("Accept-Language: zh-cn,zh;q=0.5");
                myRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
                myRequest.KeepAlive = true;
                myRequest.Proxy = null;
                myRequest.ServicePoint.Expect100Continue = false;
                NetworkCredential myCred = new NetworkCredential(i.sign, i.pwd);
                CredentialCache myCache = new CredentialCache();
                myCache.Add(new Uri("http://api.XXXXX.com"), "Basic", myCred);
                myRequest.Credentials = myCache;
                using (Stream newStream = myRequest.GetRequestStream())
                {
                  newStream.Write(data, 0, data.Length);
                  newStream.Close();
                }
                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();//返回错误
                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
                text = reader.ReadToEnd(); 
    

    用加入webconfig的方法尝试解决

    <system.net>

      <settings>

      <httpWebRequest useUnsafeHeaderParsing="true" />

      </settings>

      </system.net>

    则返回http500内部服务器错误

    2011年6月14日 3:50

答案

全部回复

  • <form method="post" action="http://api.XXXX.com/statuses/update.json">
    <input type="hidden" value="XX" name="source">
    <input type="hidden" value="XXX" name="token">
    <input type="hidden" value="sindevil" name="auth_user">
    <input type="hidden" value="84952086" name="auth_pwd">
    <input type="hidden" value="post内容" name="status">
    <input type="submit" value="我要post">
    </form>
    

    若已手动post的方式则返回正确信息
    2011年6月14日 3:52
  • myRequest.Headers.Add("Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7");
                myRequest.Headers.Add("Accept-Encoding: gzip, deflate");
                myRequest.Headers.Add("Accept-Language: zh-cn,zh;q=0.5");

    注释掉看看


    http://feiyun0112.cnblogs.com/
    2011年6月15日 2:39
    版主
  • 写那么多 Accept 干嘛,如果没有特殊要求,全部干掉。留一个 ContentType,然后把其他的 Headers 和 Accept 全部干掉试试看。
    Mark Zhou
    2011年6月15日 10:23
  • Hi 陈颉,
    试过feiyun和mazhou的建议了吗,你的问题解决了吗?
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年6月16日 8:33
    版主