473,387 Members | 1,897 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,387 software developers and data experts.

XML HTTP

Hi,

I'm trying to post XMl to a URl but when I test it the text in the request stream doesn't appear to get sent:

// Configure secure certificate & credentials
req.ClientCertificates.Add(myCert);
req.Credentials = myCache;

// Setup HTTP Request headers
req.Method = "POST";
req.ProtocolVersion=HttpVersion.Version11;
req.ContentLength = postdata.Length;
req.ContentType = "multipart/form-data; boundary=[TGWLR]";
req.KeepAlive=false;
req.Headers.Add("Authorization",encCreds);
req.AllowWriteStreamBuffering=true;

// Create stream writer
Stream strWrite = req.GetRequestStream();
StreamWriter sw = new StreamWriter(strWrite);

// Set up post data
String postdata = "\n\n--[TGWLR]\n";
postdata += "Content-disposition: form-data; name=\"tgtest001\"; filename=\"tgtest001.xml\"\n";
postdata += "Content-type: text/xml\n\n";
postdata += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
postdata += XML;
postdata += "\n--[TGWLR]--\n\n";

// POST XML --- THIS DOES NOT APPEAR TO BE WORKING
sw.Write(postdata);
sw.Flush();
sw.Close();

Any clues anybody?

Also, if there's an easier/better way of doing this can you let me know?!

Cheers,
Dave Hart
System Developer
Telco Global Ltd.
Nov 15 '05 #1
10 1711
Dave <da**@telco.co.uk> wrote:
I'm trying to post XMl to a URl but when I test it the text in the request
stream doesn't appear to get sent:

// Configure secure certificate & credentials
req.ClientCertificates.Add(myCert);
req.Credentials = myCache;

// Setup HTTP Request headers
req.Method = "POST";
req.ProtocolVersion=HttpVersion.Version11;
req.ContentLength = postdata.Length;


This line is probably the mistake. In fact, I don't know what postdata
variable it's using, as you don't declare the local variable called
postdata until later on.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Ah, damn - that's me ripping the code out!

Sorry - in the actual code the postdata line is before all this code, I just
moved it into the wrong place when copying the code.

Any other ideas?!

Cheers,

Dave

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Dave <da**@telco.co.uk> wrote:
I'm trying to post XMl to a URl but when I test it the text in the request stream doesn't appear to get sent:

// Configure secure certificate & credentials
req.ClientCertificates.Add(myCert);
req.Credentials = myCache;

// Setup HTTP Request headers
req.Method = "POST";
req.ProtocolVersion=HttpVersion.Version11;
req.ContentLength = postdata.Length;


This line is probably the mistake. In fact, I don't know what postdata
variable it's using, as you don't declare the local variable called
postdata until later on.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Dave <da**@telco.co.uk> wrote:
Ah, damn - that's me ripping the code out!

Sorry - in the actual code the postdata line is before all this code, I just
moved it into the wrong place when copying the code.


Might your XML data have any non-ASCII characters in? postdata.Length
is the length in characters, but the content length really has to be
the length in *bytes*. If you have any non-ASCII characters, they'll
end up taking more than one byte each, and thus your length will be
wrong.

(BOM, or byte-order markings, would affect this too, but I don't think
you'll end up with any.)

What does the request look like on the receiving side? (Run TcpTrace
from http://www.pocketsoap.com/tcptrace/ as a sort of proxy just to see
what the request headers etc are like.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Ok, thanks for that... great tool!

The only problem is that I'm submitting a request to a secure site which is
encrypted in the tcptrace. I created a wee app just to receive a non-secure
post and it works fine, but for some reason the secure post (which is
necessary) dies horribly.

If the data is succeeding, I guess that would indicate that the data's ok
and it's something wrong with the security? Is there any extra with
security I need to do?

Thanks,
Dave

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
Dave <da**@telco.co.uk> wrote:
Ah, damn - that's me ripping the code out!

Sorry - in the actual code the postdata line is before all this code, I just moved it into the wrong place when copying the code.


Might your XML data have any non-ASCII characters in? postdata.Length
is the length in characters, but the content length really has to be
the length in *bytes*. If you have any non-ASCII characters, they'll
end up taking more than one byte each, and thus your length will be
wrong.

(BOM, or byte-order markings, would affect this too, but I don't think
you'll end up with any.)

What does the request look like on the receiving side? (Run TcpTrace
from http://www.pocketsoap.com/tcptrace/ as a sort of proxy just to see
what the request headers etc are like.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5
Dave <da**@telco.co.uk> wrote:
Ok, thanks for that... great tool!

The only problem is that I'm submitting a request to a secure site which is
encrypted in the tcptrace. I created a wee app just to receive a non-secure
post and it works fine, but for some reason the secure post (which is
necessary) dies horribly.
Ah. Rats.
If the data is succeeding, I guess that would indicate that the data's ok
and it's something wrong with the security? Is there any extra with
security I need to do?


Well, what exactly are you seeing? How much control have you got over
what's going on at the other end?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
No control unfortunately, I'm sending to a external gateway.

However, I removed an extra line between the header and the body and now am
getting a Server error. Do you think this is due issues with the target
server rather than my posting?

Thanks,
Dave
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Dave <da**@telco.co.uk> wrote:
Ok, thanks for that... great tool!

The only problem is that I'm submitting a request to a secure site which is encrypted in the tcptrace. I created a wee app just to receive a non-secure post and it works fine, but for some reason the secure post (which is
necessary) dies horribly.


Ah. Rats.
If the data is succeeding, I guess that would indicate that the data's ok and it's something wrong with the security? Is there any extra with
security I need to do?


Well, what exactly are you seeing? How much control have you got over
what's going on at the other end?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #7
Dave <da**@telco.co.uk> wrote:
No control unfortunately, I'm sending to a external gateway.

However, I removed an extra line between the header and the body and now am
getting a Server error. Do you think this is due issues with the target
server rather than my posting?


Hard to say. What exactly do you mean by "an extra line"? A line that
definitely shouldn't be there, or just one that looks slightly dodgy?
If you use http instead of https without the extra line, what happens?

What error are you getting over https anyway? Is any of the request
stream being used?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #8
Removed an extra empty CRLF from the body...wasn't dodgy just meant there
were two as the header automatically puts a CRLF in after writing.

Getting 500 Server Error now... Going to raise it with the gateway
providers... I'll let you know...!

Cheers,
Dave

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Dave <da**@telco.co.uk> wrote:
No control unfortunately, I'm sending to a external gateway.

However, I removed an extra line between the header and the body and now am getting a Server error. Do you think this is due issues with the target
server rather than my posting?


Hard to say. What exactly do you mean by "an extra line"? A line that
definitely shouldn't be there, or just one that looks slightly dodgy?
If you use http instead of https without the extra line, what happens?

What error are you getting over https anyway? Is any of the request
stream being used?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #9
Hi,

In my HTTP headers I have "Expect: 100-continue". Is there any way I can
prevent this from appearing?

Thanks,
Dave

"Dave" <da**@telco.co.uk> wrote in message
news:Ol**************@TK2MSFTNGP12.phx.gbl...
Removed an extra empty CRLF from the body...wasn't dodgy just meant there
were two as the header automatically puts a CRLF in after writing.

Getting 500 Server Error now... Going to raise it with the gateway
providers... I'll let you know...!

Cheers,
Dave

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Dave <da**@telco.co.uk> wrote:
No control unfortunately, I'm sending to a external gateway.

However, I removed an extra line between the header and the body and now
am
getting a Server error. Do you think this is due issues with the

target server rather than my posting?


Hard to say. What exactly do you mean by "an extra line"? A line that
definitely shouldn't be there, or just one that looks slightly dodgy?
If you use http instead of https without the extra line, what happens?

What error are you getting over https anyway? Is any of the request
stream being used?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 15 '05 #10
Dave <da**@telco.co.uk> wrote:
In my HTTP headers I have "Expect: 100-continue". Is there any way I can
prevent this from appearing?


Hmm... not that I know of. That could certainly be causing problems, if
it hasn't been implemented properly on the server side.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #11

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

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
8
by: turnit \(removethis\) | last post by:
I have a login form that uses the post method to carry the information to the next page. The form works just fine in ie6.0, but fails in mozilla and fails in ie5.2 on a mac. "HTTP/1.1 400 Bad...
3
by: ashesdesign | last post by:
Hi All, I am very new to php and even newer to XML. Can anyone please shed some light on how to post XML requests via HTTP. I have been searching high and low and have come across many...
5
by: David Lozzi | last post by:
Howdy, I wrote a web service in .Net for my customer. My customer has another vendor who now has to consume it but they are not using Visual Studio. Most of their pages are jsp, and they said...
4
by: Bob Badger | last post by:
Hi, Simple question (although I guess with a complicated answer). Is HTTP an async protocol? For instance, if I send a message to a c# webservice via http what is the protocol actually doing? ...
1
by: zpinhead | last post by:
I am unable to get my downloaded extension from pecl to link up with php properly. seems like the php.so I could not use pear install http. pear claimed the extension was already installed....
3
by: webEater | last post by:
Hey, I am writing a file that reads in an external file in the web and prints it out including the response header of the http protocol. I do this to enable cross domain XMLHttpRequests. I...
1
by: rpjd | last post by:
I am completely new to this so please bear with me here. My project involves a webpage executing php scripts via an xmlhttprequest which queries a database and returns data to the webpage. This code...
1
by: rpjd | last post by:
I am having a problem getting the http.status of an xmlhttprequest. The request readystate has come back as readystate 4, but then it stops without confirming the http.status. Any help appreciated....
16
by: Harry Simpson | last post by:
I've been away from ASPNET - I open up a new Web app in VS2008 and go into properties and select to use IIS instead of the personal web server. Then I run in debug mode and it says I have to set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.