Solved

internal server error 500 when using http post containing %0A%3C

Posted on 2008-06-19
2
1,182 Views
Last Modified: 2013-12-16
Hi

I am trying to perform an HTTP POST to a website. Every time i do the POST i get a response of 500. Internal server error.

I have found out that the reason i am getting the error is because the POST contains the string:

%0A%3C

This is a line feed and a < sign.

For some reason i am unable to post this data when it is a requirement for me. If i use %0A%3E (which is line feed and > sign) it works.

Does anyone know why this would happen?

Any help would be appreciated. I have attached the code that i am using.

I am running Microsoft Visual Studio 2005. .Net 2.0 Service Pack 1, Windows XP and IIS 5.1

(i tried it on server 2003 with iis 6.0 and had the same error)

Apyreal
static void Main(string[] args)
        {
           string query = "?%0A%3Chey";
            string a = HTTPCallback("url", query, "POST");
            Console.WriteLine(a);
            Console.ReadLine();
        }
 
        // simple generic http get/post request function
        static string HTTPCallback(string uri, string query, string method)
        {
            string output = string.Empty;
            try
            {
                // request
                WebRequest request;
                // do a POST if requested, otherwise default to a GET
                if (method.ToUpper() == "POST")
                {
                    request = WebRequest.Create(uri);
                    request.Method = "POST";
                    byte[] buffer = Encoding.UTF8.GetBytes(query);
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.ContentLength = buffer.Length;
                    // add form data to request stream
                    System.IO.Stream requestStream = request.GetRequestStream();
                    requestStream.Write(buffer, 0, buffer.Length);
                    requestStream.Flush();
                    requestStream.Close();
                }
                else
                {
                    request = WebRequest.Create(uri + query);
                    request.Method = "GET";
                }
                // response
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                System.IO.Stream responseStream = response.GetResponseStream();
                StreamReader responseReader = new StreamReader(responseStream);
                // output
                output = responseReader.ReadToEnd();
                // clean-up
                responseReader.Close();
                responseStream.Close();
                response.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
 
            return output;
        }

Open in new window

0
Comment
Question by:Apyreal
2 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 21821725
I'm not sure, but wouldn't you need to encode that like &lt; for <
like in html, to keep the page from thinking "<" is the beginning of a tag..that it subsequently won't find?
0
 
LVL 1

Accepted Solution

by:
Apyreal earned 0 total points
ID: 21821787
nope, actually. the it is already encoded. I found the problem about 5 minutes ago. IIS was treating %0A%3C as a possible dangerous request, so it would always fail it.

Fix was to place ValidateRequest="false" in the page to where i am posting. Not a perfect fix but it is the only one that works
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question