473,503 Members | 7,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using HttpWebResponse to get POST variables

Hi all,

Fairly straight forward problem. I have a Post using HttpWebRequest
that posts data to a server. That server then posts data back to me.
Posting the data's not a problem, however I'm wondering if there is an
easy way to read back the variables that are returned. If not, I'm
left creating a parse routine which is not the end of the world but I
just want to be as programatically correct as I can be.

Code:

StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
System.Text.Encoding.ASCII);
//Convert the stream to a string
string s = sr.ReadToEnd();
sr.Close();
Response.Write(s);

RETURNS:

s ="trnApproved=1&trnId=10000843&messageId=1&message Text=Approved&authCode=TEST&errorType=N&errorField s=&avsProcessed=0&avsId=0&avsResult=0&avsAddrMatch =0&avsPostalMatch=0&avsMessage=Address+Verificatio n+not+performed+for+this+transaction%2E"

I'd just like a way to read Request["trnApproved"] or
Request["messageText"] - Any ideas?

Thanks,
DB
Nov 15 '05 #1
2 24685
I create a helper class , to strore the request array

using System;
using System.Collections;
using System.Collections.Specialized;

namespace Erymuzuan.WinContainer
{
/// <summary>
/// Summary description for BrowserInfo.
/// </summary>
public class BrowserInfo : NameObjectCollectionBase
{
/// <summary> </summary>
private DictionaryEntry m_de = new DictionaryEntry();

/// <summary>
/// ctor
/// </summary>
/// <example>
/// new BrowserInfo("myq=msa&sw=12&id=1232");
/// </example>
/// <param name="postData">query string pairs
/// </param>
public BrowserInfo(string postData)
{
string name;
string val;

foreach ( string s in postData.Split('&'))
{
name = s.Substring(0, s.IndexOf("=") );
val = s.Substring(s.IndexOf("=") + 1 , s.Length - (name.Length + 1));

// add it
BaseAdd(name, val);
}

}
/// <summary> Gets a key-and-value pair (DictionaryEntry) using an
index.</summary>
public DictionaryEntry this[ int index ]
{
get
{
m_de.Key = BaseGetKey(index);
m_de.Value = BaseGet(index);
return( m_de );
}
}

//
/// <summary> Gets or sets the value associated with the specified
key.</summary>
public string this[ string key ]
{
get { return( BaseGet( key ).ToString() ); }
set { BaseSet( key, value ); }
}

//
/// <summary> Gets a String array that contains all the keys in the
collection.</summary>
public String[] AllKeys
{
get { return( this.BaseGetAllKeys() ); }
}

//
/// <summary> Gets an Object array that contains all the values in the
collection.</summary>
public Array AllValues
{
get { return( this.BaseGetAllValues() ); }
}

//
/// <summary> Gets a value indicating if the collection contains keys that
are not null.</summary>
public Boolean HasKeys
{
get { return( this.BaseHasKeys() ); }
}
/// <summary>
/// Adds an entry to the collection.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void Add( String key, Object value )
{
this.BaseAdd( key, value );
}

}// class
}
--
Erymuzuan Mustapa
Inter Virtual Sdn. Bhd.
See MIND at http://www.MIND.com.my

"David Billson" <da***********@rtraction.com> wrote in message
news:9b**************************@posting.google.c om...
Hi all,

Fairly straight forward problem. I have a Post using HttpWebRequest
that posts data to a server. That server then posts data back to me.
Posting the data's not a problem, however I'm wondering if there is an
easy way to read back the variables that are returned. If not, I'm
left creating a parse routine which is not the end of the world but I
just want to be as programatically correct as I can be.

Code:

StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
System.Text.Encoding.ASCII);
//Convert the stream to a string
string s = sr.ReadToEnd();
sr.Close();
Response.Write(s);

RETURNS:

s ="trnApproved=1&trnId=10000843&messageId=1&message Text=Approved&authCode=TES
T&errorType=N&errorFields=&avsProcessed=0&avsId=0& avsResult=0&avsAddrMatch=0
&avsPostalMatch=0&avsMessage=Address+Verification+ not+performed+for+this+tra
nsaction%2E"
I'd just like a way to read Request["trnApproved"] or
Request["messageText"] - Any ideas?

Thanks,
DB

Nov 15 '05 #2
Since you are programatically going to another web page, chances are you are
doing this to get data? If so, and if you have control over it - the server
you are calling - should return XML. That way all your data will be nice and
organized when it do a GetResponseStream(). Food for thought...
"David Billson" <da***********@rtraction.com> wrote in message
news:9b**************************@posting.google.c om...
Hi all,

Fairly straight forward problem. I have a Post using HttpWebRequest
that posts data to a server. That server then posts data back to me.
Posting the data's not a problem, however I'm wondering if there is an
easy way to read back the variables that are returned. If not, I'm
left creating a parse routine which is not the end of the world but I
just want to be as programatically correct as I can be.

Code:

StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
System.Text.Encoding.ASCII);
//Convert the stream to a string
string s = sr.ReadToEnd();
sr.Close();
Response.Write(s);

RETURNS:

s ="trnApproved=1&trnId=10000843&messageId=1&message Text=Approved&authCode=TES
T&errorType=N&errorFields=&avsProcessed=0&avsId=0& avsResult=0&avsAddrMatch=0
&avsPostalMatch=0&avsMessage=Address+Verification+ not+performed+for+this+tra
nsaction%2E"
I'd just like a way to read Request["trnApproved"] or
Request["messageText"] - Any ideas?

Thanks,
DB

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2095
by: Denny Rue | last post by:
I’ve created VB code to download files from a web site through the use of HTTPWebRequest, HTTPWebResponse and BinaryReader. The HTTPWebRequest has a TimeOut property to limit how long it waits...
3
11267
by: Paul M | last post by:
Hi Sorry if this is posted in the wrong group but I'm brand new to this area. Basically I've got to post some XML documents to an external server using HTTP web request (POST, not GET) and be able...
1
5839
by: Vasu | last post by:
Hi, I have a requirement to download a file from the web site using a client tool. Iam writing a C# program to download using WebRequest, HttpRequest, WebResponse and so on. The problem...
0
9188
by: Peter Qian | last post by:
Hi, I'm working on a windows form based program that can log into a web service (Apache based, https is used for auth). I was able to post the login data and obtain a sessionID. However I'm not...
0
3196
by: Anthony | last post by:
Hi all, I am just trying to set up a form post to worldppay and finding it surprisingly difficult.. What i would like is to gather all of the variables needed in c# codebehind and then send them...
7
4244
by: | last post by:
Hello, I would like to do the following from a asp.net button click: <form method="POST" action="https://www.1234.com/trans_center/gateway/direct.cgi"> <input type="hidden" name="Merchant"...
7
17255
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
0
1513
by: sanjaygupta11 | last post by:
I am using httpwebrequest and httpwebresponse objects for sending data to remote appication by post and receiving the response from there. I am using this code in my windows application which will...
4
3313
by: JVNewbie | last post by:
I'm attempting to test an aspx module that will receive XML data from a web service (the receiver module). I want to be able to test this portion before attempting to create the Web Service that will...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.