473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Stream.Write / encoding problem?

Hi, I am trying to send an UTF-8 XML string to remote resource via
HttpWebRequest using POST method, which means that I need to get the
request stream and write my XML string to it. No problems here.

The problem that I'm running into is that the "+" sign that one of the
XML elements contains is lost somehow in the transaction. I verified
that the "+" is actually in the XML string prior to getting bytes, and
writing to stream:

byte[] data;
UTF8Encoding encoding = new UTF8Encoding();

data = encoding.GetBytes(formData) //formData is a string containg XML

//here request is created
....

//now add the form data to the request
//first, get the request stream
Stream stream = request.GetRequestStream();

//write data to the stream
stream.Write(data, 0, data.Length);

Any ideas why the "+" sign is lost? If I convert the byte array (data)
back into string, the "+" is there. The remote resource does not get
it, however.

If I send the same XML via reqular web form post, rather than using the
server-side HttpWebRequest call, everything works fine. This leads me
to believe that I am not doing something properly as far as encoding is
concerned. I would appreciate any pointers.

This is how the XML is constructed. I'm concatonating the string
essentially, inserting data I collected from web from into placeholders
at later time.

private string GetXMLRequest()
{
string xml = String.Empty;

xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
xml += "<TranxRequest>";
xml += "<MerchantNumber>{0}</MerchantNumber>";
xml += "<Products>{1}</Products>";
xml += "<xxxName>{2}</xxxName>";
xml += "<xxxCompany>{3}</xxxCompany>";
xml += "<xxxAddress>{4}</xxxAddress>";
xml += "<xxxCity>{5}</xxxCity>";
xml += "<xxxProvince>{6}</xxxProvince>";
xml += "<xxxPostal>{7}</xxxPostal>";
xml += "<xxxCountry>{8}</xxxCountry>";
xml += "<xxxPhone>{9}</xxxPhone>";
xml += "<xxxEmail>{10}</xxxEmail>";
xml += "<xxxCard_Number>{11}</xxxCard_Number>";
xml += "<xxxCCMonth>{12}</xxxCCMonth>";
xml += "<xxxCCYear>{13}</xxxCCYear>";
xml += "<CVV2Indicator>{14}</CVV2Indicator>";
xml += "<CVV2>{15}</CVV2>";
xml += "<xxxShippingName>{16}</xxxShippingName>";
xml += "<xxxShippingCompany>{17}</xxxShippingCompany>";
xml += "<xxxShippingAddress>{18}</xxxShippingAddress>";
xml += "<xxxShippingCity>{19}</xxxShippingCity>";
xml += "<xxxShippingPostal>{20}</xxxShippingPostal>";
xml += "<xxxShippingCountry>{21}</xxxShippingCountry>";
xml += "<xxxShippingPhone>{22}</xxxShippingPhone>";
xml += "<xxxShippingEmail>{23}</xxxShippingEmail>";
xml += "</TranxRequest>";

return xml;
}

ib.
Nov 18 '05 #1
0 1046

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

Similar topics

0
by: hs | last post by:
Hi I got a 'stream not readable' exception. I'd appreciate if some one can tell me how i can overcome this. thanks My Exception --------------
3
by: Brad Wood | last post by:
I have an XML document in a file (e:\bobo.xml) saved using unicode encoding with declaration: <?xml version="1.0" encoding="UTF-16"?> I can load that file into an XmlTextReader and read it just...
4
by: Fresh_Air_Rider | last post by:
Hi In the "good old" Classic ASP days, I used to stream records from a SQL Server database out to the user's browser in CSV format by using a combination of COALESCE and the ADODB.Stream object....
10
by: John Kraft | last post by:
Hello all, I'm experiencing some, imo, strange behavior with the StreamReader object I am using in the code below. Summary is that I am downloading a file from a website and saving it to disk...
3
by: markclinn | last post by:
I have a device in the field that I access by the stream method. I open the Stream and do the following: 1. stream.write a character to the device. 2. stream.read the information from the...
0
by: Janusz Nykiel | last post by:
I've stumbled upon unexpected behavior of the .NET 2.0 System.Xml.XmlWriter class when using it to write data to a binary stream (System.IO.Stream). If the amount of data is less than a certain...
3
by: Sir Psycho | last post by:
Hi, For some reason, when i step over this code, it returns the full byte stream im expecting from the server, however when I let it run with no intervention, it only seems to grab a small chunk...
2
by: Mike P2 | last post by:
I made a Stream-inheriting class that just removes the tabs (actually the 4 spaces VS prefers to use) from the beginning of lines and empty lines. At first I was having trouble with it adding a...
0
by: Iridium | last post by:
Greetings, I am trying to get a JPG Frame from a MJPG Stream. A MJPG is basically a stream of JPGs which are splitted by a special boundary string. So I tried to get the stream, split it by the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.