开发者

Reuest.InputStream.Length is 0 and RequestType is Get

开发者 https://www.devze.com 2023-03-07 11:33 出处:网络
I am trying to use httpwebrequest to POST a simple XML string to another webserver\'s web page in ASP.NET.

I am trying to use httpwebrequest to POST a simple XML string to another webserver's web page in ASP.NET.

Here is the sample code:

 public static bool Send()
 {
    string xml = "<Root><SEQNO>7</SEQNO></Root>";
    Byte[] bytes = System.Text.Encoding.UTF8.GetBytes(xml);
    HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create("Url");
    objWebRequest.ContentType = "text/xml";
    objWebRequest.Method = WebRequestMethods.Http.Post;
    objWebRequest.Timeout = 10000;
    objWebRequest.ContentLength = bytes.Length;

    Stream objRequestStream = null;
    objRequestStream = objWebRequest.GetRequestStream();
    objRequestStream.Write(bytes, 0, bytes.Length);
    objRequestStream.Close();

    HttpWebResponse objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();

    if (objWebResponse.StatusCode == HttpStatusCode.OK)
    {
        objWebResponse.Close();
        return true;

    }
    else
    {
        return false;
    }
  }

This code runs OK, b开发者_开发问答ut on the page where it post to I check Request.RequestType which always gives 'Get'and Request. InputStream is not null but its length is always 0. I am not able to receive the string.

What's wrong here? Am I missing something? Please suggest how I can fix this problem.


This is strange but I found the solution myself, its in web.config,

When I use cookieless="AutoDetect" or cookieless="True", I had Request type on receiver always as Get and Request.InputStream.Length was 0. When I set to it to false, everything is fine.

So far it worked but I would like to dig this more later.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号