0

I ran into a problem. I am .Net Developer and don't know about php, I am working on a CRM which has an API. My Client says it should be simple page should work with simple post. now i don't understand how i can do a simple Post in .Net. I have created an asp.net WebForm. All is working well. The only thing that i have problem with is that i have to return a list of parameters to response. I am using

Response.Write("100 - Click Recorded Successfully.");

but this return a full html Document with the parameter string at the top of the document. I saw one php Api which return only the prameter string like this with out HTML Document:

response=1
    &responsetext=SUCCESS
    &authcode=123456
    &transactionid=2154229522
    &avsresponse=N
    &cvvresponse=N
    &orderid=3592
    &type=sale
    &response_code=100

can some one suggest me any better way how i can do this. I found many article that explains how to do a simple Get Post in .Net but none of these solved my problem.

Update:

this is the code that i am using from another application to call the page and get response stream

            string result = "";
            WebRequest objRequest = WebRequest.Create(url + query);
            objRequest.Method = "POST";
            objRequest.ContentLength = 0;
            objRequest.Headers.Add("x-ms-version", "2012-08-01");
            objRequest.ContentType = "application/xml";

            WebResponse objResponse = objRequest.GetResponse();
            using (StreamReader sr =
               new StreamReader(objResponse.GetResponseStream()))
            {
                result = sr.ReadToEnd();

                // Close and clean up the StreamReader
                sr.Close();
            }
            string temp = result;

where url + query is the address to my page. The result shows this code http://screencast.com/t/eKn4cckXc. I want to get the header line only, that is "100 - Click Recorded Successfully."

Waqas Ahmed
  • 48
  • 2
  • 12
  • possible duplicate of [Prevent aspx-page rendering](http://stackoverflow.com/questions/10980435/prevent-aspx-page-rendering) – CodeCaster Feb 05 '14 at 13:20

1 Answers1

0

You have two options. First is to clear whatever response was already generated on the page, write the text, and then end the response so that nothing else added:

Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "text/plain");
Response.Write(Request.Url.Query);
Response.End();

That is if you want to process it on the Page. However a better approach would be to implement Http Handler, in which case all you need to do is:

public void ProcessRequest
{
    Response.AddHeader("Content-Type", "text/plain");
    Response.Write(Request.Url.Query);
}
Andrei
  • 55,890
  • 9
  • 87
  • 108
  • None of these worked for me, may be i didn't explain correctly, the page i am working on will be called by another Application. and also instead of Request.Url.Query i will be passing some custom message to the application client. the Response.End() throws an exception, "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack. string" – Waqas Ahmed Feb 06 '14 at 19:47